Commit aafca9f7 by mushishixian

整理

parent 9021543e
Showing with 328 additions and 572 deletions
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.24.0
// protoc v3.12.1
// source: Common.proto
package Course
import (
proto "github.com/golang/protobuf/proto"
timestamp "github.com/golang/protobuf/ptypes/timestamp"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// This is a compile-time assertion that a sufficiently up-to-date version
// of the legacy proto package is being used.
const _ = proto.ProtoPackageIsVersion4
type Timestamp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Timestamp *timestamp.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
Timestr string `protobuf:"bytes,2,opt,name=timestr,proto3" json:"timestr,omitempty"`
}
func (x *Timestamp) Reset() {
*x = Timestamp{}
if protoimpl.UnsafeEnabled {
mi := &file_Common_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Timestamp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Timestamp) ProtoMessage() {}
func (x *Timestamp) ProtoReflect() protoreflect.Message {
mi := &file_Common_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Timestamp.ProtoReflect.Descriptor instead.
func (*Timestamp) Descriptor() ([]byte, []int) {
return file_Common_proto_rawDescGZIP(), []int{0}
}
func (x *Timestamp) GetTimestamp() *timestamp.Timestamp {
if x != nil {
return x.Timestamp
}
return nil
}
func (x *Timestamp) GetTimestr() string {
if x != nil {
return x.Timestr
}
return ""
}
var File_Common_proto protoreflect.FileDescriptor
var file_Common_proto_rawDesc = []byte{
0x0a, 0x0c, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06,
0x43, 0x6f, 0x75, 0x72, 0x73, 0x65, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d,
0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x5f, 0x0a, 0x09, 0x54, 0x69, 0x6d, 0x65, 0x73,
0x74, 0x61, 0x6d, 0x70, 0x12, 0x38, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d,
0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74,
0x61, 0x6d, 0x70, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x18,
0x0a, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
0x07, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_Common_proto_rawDescOnce sync.Once
file_Common_proto_rawDescData = file_Common_proto_rawDesc
)
func file_Common_proto_rawDescGZIP() []byte {
file_Common_proto_rawDescOnce.Do(func() {
file_Common_proto_rawDescData = protoimpl.X.CompressGZIP(file_Common_proto_rawDescData)
})
return file_Common_proto_rawDescData
}
var file_Common_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_Common_proto_goTypes = []interface{}{
(*Timestamp)(nil), // 0: Course.Timestamp
(*timestamp.Timestamp)(nil), // 1: google.protobuf.Timestamp
}
var file_Common_proto_depIdxs = []int32{
1, // 0: Course.Timestamp.timestamp:type_name -> google.protobuf.Timestamp
1, // [1:1] is the sub-list for method output_type
1, // [1:1] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_Common_proto_init() }
func file_Common_proto_init() {
if File_Common_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_Common_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Timestamp); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_Common_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_Common_proto_goTypes,
DependencyIndexes: file_Common_proto_depIdxs,
MessageInfos: file_Common_proto_msgTypes,
}.Build()
File_Common_proto = out.File
file_Common_proto_rawDesc = nil
file_Common_proto_goTypes = nil
file_Common_proto_depIdxs = nil
}
package Course
import (
"database/sql/driver"
"fmt"
"github.com/golang/protobuf/ptypes"
"time"
)
//db 数据 =>go类型
func (this *Timestamp) Scan(value interface{}) error {
switch t := value.(type) {
case time.Time:
var err error
this.Timestamp, err = ptypes.TimestampProto(t)
if err != nil {
return err
}
default:
return fmt.Errorf("timestamp error")
}
return nil
}
// insert update 把go数据类型 =>db类型
func (this Timestamp) Value() (driver.Value, error) {
return ptypes.Timestamp(this.Timestamp)
}
...@@ -2,25 +2,25 @@ package Mapper ...@@ -2,25 +2,25 @@ package Mapper
import ( import (
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
"jtthink/boot" "search_server/pkg/vars"
"jtthink/Vars" "search_server/pkg/mysql"
) )
func GetCourseList() *gorm.DB { func GetCourseList() *gorm.DB {
return boot.GetDB().Table(Vars.Table_CourseMain). return mysql.GetDB().Table(vars.Table_CourseMain).
Order("course_id desc").Limit(3) Order("course_id desc").Limit(3)
} }
const course_list="select * from course_main order by course_id desc limit ?" const course_list = "select * from course_main order by course_id desc limit ?"
func GetCourseListBySql(args ...interface{}) *gorm.DB{
return boot.GetDB().Raw(course_list,args...) func GetCourseListBySql(args ...interface{}) *gorm.DB {
return mysql.GetDB().Raw(course_list, args...)
} }
func GetCourseDetail(course_id int ) *gorm.DB{ func GetCourseDetail(course_id int) *gorm.DB {
return boot.GetDB().Table(Vars.Table_CourseMain).Where("course_id=?",course_id) return mysql.GetDB().Table(vars.Table_CourseMain).Where("course_id=?", course_id)
} }
//取计数表 //取计数表
func GetCourseCounts(course_id int ) *gorm.DB{ func GetCourseCounts(course_id int) *gorm.DB {
return boot.GetDB().Table(Vars.Table_CourseCounts).Where("course_id=?",course_id) return mysql.GetDB().Table(vars.Table_CourseCounts).Where("course_id=?", course_id)
} }
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.23.0
// protoc v3.10.1
// source: Users.proto
package Users
import (
proto "github.com/golang/protobuf/proto"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// This is a compile-time assertion that a sufficiently up-to-date version
// of the legacy proto package is being used.
const _ = proto.ProtoPackageIsVersion4
type UserRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
}
func (x *UserRequest) Reset() {
*x = UserRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_Users_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *UserRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UserRequest) ProtoMessage() {}
func (x *UserRequest) ProtoReflect() protoreflect.Message {
mi := &file_Users_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use UserRequest.ProtoReflect.Descriptor instead.
func (*UserRequest) Descriptor() ([]byte, []int) {
return file_Users_proto_rawDescGZIP(), []int{0}
}
func (x *UserRequest) GetId() string {
if x != nil {
return x.Id
}
return ""
}
type UserResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Ret string `protobuf:"bytes,2,opt,name=ret,proto3" json:"ret,omitempty"`
}
func (x *UserResponse) Reset() {
*x = UserResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_Users_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *UserResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UserResponse) ProtoMessage() {}
func (x *UserResponse) ProtoReflect() protoreflect.Message {
mi := &file_Users_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use UserResponse.ProtoReflect.Descriptor instead.
func (*UserResponse) Descriptor() ([]byte, []int) {
return file_Users_proto_rawDescGZIP(), []int{1}
}
func (x *UserResponse) GetRet() string {
if x != nil {
return x.Ret
}
return ""
}
var File_Users_proto protoreflect.FileDescriptor
var file_Users_proto_rawDesc = []byte{
0x0a, 0x0b, 0x55, 0x73, 0x65, 0x72, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x55,
0x73, 0x65, 0x72, 0x73, 0x22, 0x1d, 0x0a, 0x0b, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x02, 0x69, 0x64, 0x22, 0x20, 0x0a, 0x0c, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
0x52, 0x03, 0x72, 0x65, 0x74, 0x32, 0x40, 0x0a, 0x0b, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x12, 0x31, 0x0a, 0x04, 0x54, 0x65, 0x73, 0x74, 0x12, 0x12, 0x2e, 0x55,
0x73, 0x65, 0x72, 0x73, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x13, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x73, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_Users_proto_rawDescOnce sync.Once
file_Users_proto_rawDescData = file_Users_proto_rawDesc
)
func file_Users_proto_rawDescGZIP() []byte {
file_Users_proto_rawDescOnce.Do(func() {
file_Users_proto_rawDescData = protoimpl.X.CompressGZIP(file_Users_proto_rawDescData)
})
return file_Users_proto_rawDescData
}
var file_Users_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_Users_proto_goTypes = []interface{}{
(*UserRequest)(nil), // 0: Users.UserRequest
(*UserResponse)(nil), // 1: Users.UserResponse
}
var file_Users_proto_depIdxs = []int32{
0, // 0: Users.UserService.Test:input_type -> Users.UserRequest
1, // 1: Users.UserService.Test:output_type -> Users.UserResponse
1, // [1:2] is the sub-list for method output_type
0, // [0:1] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_Users_proto_init() }
func file_Users_proto_init() {
if File_Users_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_Users_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*UserRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_Users_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*UserResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_Users_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_Users_proto_goTypes,
DependencyIndexes: file_Users_proto_depIdxs,
MessageInfos: file_Users_proto_msgTypes,
}.Build()
File_Users_proto = out.File
file_Users_proto_rawDesc = nil
file_Users_proto_goTypes = nil
file_Users_proto_depIdxs = nil
}
set MICRO_REGISTRY=etcd set MICRO_REGISTRY=etcd
set MICRO_REGISTRY_ADDRESS=192.168.2.232:2379 set MICRO_REGISTRY_ADDRESS=192.168.2.232:2379
go run cmd/course_http_server.go --server_address :9000 go run ../cmd/course_http_server.go --server_address :9000
\ No newline at end of file \ No newline at end of file
::protoc --proto_path=protos --micro_out=users --go_out=users users.proto
protoc --proto_path=protos --micro_out=course --go_out=course course.proto
protoc-go-inject-tag -input=course/course.pb.go
protoc --proto_path=protos --micro_out=course --go_out=course common.proto
protoc --proto_path=protos --micro_out=course --go_out=course course_topic.proto
protoc-go-inject-tag -input=course/course_topic.pb.go
\ No newline at end of file
package boot
import (
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
"jtthink/pkg/config"
)
//mysql相关
var mysqlDb *gorm.DB
func InitMysql() error {
var err error
userName := config.Get("database.user_name").String()
password := config.Get("database.password").String()
host := config.Get("database.host").String()
database := config.Get("database.database").String()
mysqlDb, err = gorm.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s:3306)/%s?charset=utf8&parseTime=True&loc=Local",
userName, password, host, database))
if err != nil {
mysqlDb = nil
return NewFatalError(err.Error()) //这里返回致命异常
}
mysqlDb.SingularTable(true)
mysqlDb.DB().SetMaxIdleConns(10)
mysqlDb.DB().SetMaxOpenConns(100)
mysqlDb.LogMode(true)
return nil
}
func GetDB() *gorm.DB {
return mysqlDb
}
package boot
type FatalError struct {
ErrMsg string
}
func (err *FatalError) Error() string {
return err.ErrMsg
}
func NewFatalError( msg string) *FatalError {
return &FatalError{ ErrMsg: msg}
}
func IsFatalError(err error) bool {
if _,ok:=err.(*FatalError);ok{
return true
}
return false
}
\ No newline at end of file
package boot package boot
import ( import (
"jtthink/pkg/config" "search_server/pkg/config"
"jtthink/pkg/gredis" "search_server/pkg/gredis"
"jtthink/pkg/mysql" "search_server/pkg/mysql"
) )
func Boot() (err error) { func Boot() (err error) {
......
...@@ -3,9 +3,9 @@ package main ...@@ -3,9 +3,9 @@ package main
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/micro/go-micro/v2/web" "github.com/micro/go-micro/v2/web"
"jtthink/boot" "search_server/boot"
"jtthink/framework/gin_" "search_server/framework/gin_"
_ "jtthink/lib" _ "search_server/lib"
"log" "log"
) )
......
...@@ -4,7 +4,7 @@ import ( ...@@ -4,7 +4,7 @@ import (
"context" "context"
"github.com/micro/go-micro/v2/client/grpc" "github.com/micro/go-micro/v2/client/grpc"
"github.com/micro/go-micro/v2/web" "github.com/micro/go-micro/v2/web"
"jtthink/Course" "search_server/Course"
"log" "log"
"net/http" "net/http"
) )
......
...@@ -2,8 +2,8 @@ package main ...@@ -2,8 +2,8 @@ package main
import ( import (
"github.com/micro/go-micro/v2" "github.com/micro/go-micro/v2"
"jtthink/Course" "search_server/protopb/course"
"jtthink/service" "search_server/service"
"log" "log"
) )
...@@ -14,7 +14,7 @@ func main() { ...@@ -14,7 +14,7 @@ func main() {
micro.Name("go.micro.api.jtthink.course")) micro.Name("go.micro.api.jtthink.course"))
cService.Init() cService.Init()
err:=Course.RegisterCourseServiceHandler(cService.Server(),service.NewCourseServiceImpl()) err:=course.RegisterCourseServiceHandler(cService.Server(),service.NewCourseServiceImpl())
if err!=nil{ if err!=nil{
log.Fatal(err) log.Fatal(err)
} }
......
...@@ -3,10 +3,10 @@ package main ...@@ -3,10 +3,10 @@ package main
import ( import (
"context" "context"
"github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client"
"jtthink/Course" "search_server/Course"
"github.com/micro/go-micro/v2" "github.com/micro/go-micro/v2"
"jtthink/Users" "search_server/Users"
"log" "log"
) )
......
module jtthink module search_server
go 1.14 go 1.14
...@@ -18,7 +18,7 @@ require ( ...@@ -18,7 +18,7 @@ require (
google.golang.org/appengine v1.6.3 // indirect google.golang.org/appengine v1.6.3 // indirect
google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece // indirect google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece // indirect
google.golang.org/grpc v1.29.1 // indirect google.golang.org/grpc v1.29.1 // indirect
google.golang.org/protobuf v1.24.0 google.golang.org/protobuf v1.24.0 // indirect
gopkg.in/ini.v1 v1.51.0 // indirect gopkg.in/ini.v1 v1.51.0 // indirect
) )
......
...@@ -2,75 +2,78 @@ package lib ...@@ -2,75 +2,78 @@ package lib
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"jtthink/framework/gin_" "search_server/framework/gin_"
"jtthink/Course" "search_server/protopb/course"
"jtthink/service" "search_server/service"
) )
func init() { func init() {
courseService:=service.NewCourseServiceImpl() courseService := service.NewCourseServiceImpl()
gin_.NewBuilder().WithService(courseService). gin_.NewBuilder().WithService(courseService).
WithMiddleware(Check_Middleware()). WithMiddleware(Check_Middleware()).
WithMiddleware(Cors_Middleware()). WithMiddleware(Cors_Middleware()).
WithEndpoint(Courselist_Endpoint(courseService)). WithEndpoint(Courselist_Endpoint(courseService)).
WithRequest(Courselist_Request()). WithRequest(Courselist_Request()).
WithResponse(Course_Response()).Build("/course","GET") WithResponse(Course_Response()).Build("/course", "GET")
gin_.NewBuilder().WithService(courseService). gin_.NewBuilder().WithService(courseService).
WithMiddleware(Check_Middleware()). WithMiddleware(Check_Middleware()).
WithEndpoint(Coursedetail_Endpoint(courseService)). WithEndpoint(Coursedetail_Endpoint(courseService)).
WithRequest(Coursedetail_Request()). WithRequest(Coursedetail_Request()).
WithResponse(Course_Response()).Build("/detail/:course_id","GET") WithResponse(Course_Response()).Build("/detail/:course_id", "GET")
} }
//详细相关 //详细相关
func Coursedetail_Endpoint(c *service.CourseServiceImpl) gin_.Endpoint { func Coursedetail_Endpoint(c *service.CourseServiceImpl) gin_.Endpoint {
return func(context *gin.Context, request interface{}) (response interface{}, err error) { return func(context *gin.Context, request interface{}) (response interface{}, err error) {
rsp:=&Course.DetailResponse{Course:new(Course.CourseModel),Counts:make([]*Course.CourseCounts,0)} rsp := &course.DetailResponse{Course: new(course.CourseModel), Counts: make([]*course.CourseCounts, 0)}
err=c.GetDetail(context,request.(*Course.DetailRequest),rsp) err = c.GetDetail(context, request.(*course.DetailRequest), rsp)
return rsp,err return rsp, err
} }
} }
//这个函数的作用是怎么处理请求 //这个函数的作用是怎么处理请求
func Coursedetail_Request() gin_.EncodeRequestFunc{ func Coursedetail_Request() gin_.EncodeRequestFunc {
return func(context *gin.Context) (i interface{}, e error) { return func(context *gin.Context) (i interface{}, e error) {
bReq:=&Course.DetailRequest{} bReq := &course.DetailRequest{}
err:=context.BindUri(bReq) err := context.BindUri(bReq)
if err!=nil{ if err != nil {
return nil,err return nil, err
} }
err=context.BindHeader(bReq) err = context.BindHeader(bReq)
if err!=nil{ if err != nil {
return nil,err return nil, err
} }
return bReq,nil return bReq, nil
} }
} }
//获取列表相关 //获取列表相关
func Courselist_Endpoint(c *service.CourseServiceImpl) gin_.Endpoint { func Courselist_Endpoint(c *service.CourseServiceImpl) gin_.Endpoint {
return func(context *gin.Context, request interface{}) (response interface{}, err error) { return func(context *gin.Context, request interface{}) (response interface{}, err error) {
rsp:=&Course.ListResponse{} rsp := &course.ListResponse{}
err=c.ListForTop(context,request.(*Course.ListRequest),rsp) err = c.ListForTop(context, request.(*course.ListRequest), rsp)
return rsp,err return rsp, err
} }
} }
//这个函数的作用是怎么处理请求 //这个函数的作用是怎么处理请求
func Courselist_Request() gin_.EncodeRequestFunc{ func Courselist_Request() gin_.EncodeRequestFunc {
return func(context *gin.Context) (i interface{}, e error) { return func(context *gin.Context) (i interface{}, e error) {
bReq:=&Course.ListRequest{} bReq := &course.ListRequest{}
err:=context.BindQuery(bReq) //使用的是query 参数 err := context.BindQuery(bReq) //使用的是query 参数
if err!=nil{ if err != nil {
return nil,err return nil, err
} }
return bReq,nil return bReq, nil
} }
} }
//这个函数作用是:怎么处理响应结果 //这个函数作用是:怎么处理响应结果
func Course_Response() gin_.DecodeResponseFunc { func Course_Response() gin_.DecodeResponseFunc {
return func(context *gin.Context, res interface{}) error { return func(context *gin.Context, res interface{}) error {
context.JSON(200,res) context.JSON(200, res)
return nil return nil
} }
} }
...@@ -2,9 +2,9 @@ package lib ...@@ -2,9 +2,9 @@ package lib
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"jtthink/framework/gin_" "search_server/framework/gin_"
"jtthink/Course" "search_server/protopb/course"
"jtthink/service" "search_server/service"
) )
func init() { func init() {
...@@ -14,21 +14,19 @@ func init() { ...@@ -14,21 +14,19 @@ func init() {
WithEndpoint(CourseTopicList_Endpoint(courseService)). WithEndpoint(CourseTopicList_Endpoint(courseService)).
WithRequest(CourseTopicList_Request()). WithRequest(CourseTopicList_Request()).
WithResponse(Course_Response()).Build("/topic/:cid","GET") WithResponse(Course_Response()).Build("/topic/:cid","GET")
} }
func CourseTopicList_Endpoint(c *service.CourseTopicServiceImpl) gin_.Endpoint { func CourseTopicList_Endpoint(c *service.CourseTopicServiceImpl) gin_.Endpoint {
return func(context *gin.Context, request interface{}) (response interface{}, err error) { return func(context *gin.Context, request interface{}) (response interface{}, err error) {
rsp:=&Course.TopicResponse{Result:make([]*Course.CourseTopic,0)} rsp:=&course.TopicResponse{Result:make([]*course.CourseTopic,0)}
err=c.GetTopic(context,request.(*Course.TopicRequest),rsp) err=c.GetTopic(context,request.(*course.TopicRequest),rsp)
return rsp,err return rsp,err
} }
} }
//这个函数的作用是怎么处理请求 //这个函数的作用是怎么处理请求
func CourseTopicList_Request() gin_.EncodeRequestFunc{ func CourseTopicList_Request() gin_.EncodeRequestFunc{
return func(context *gin.Context) (i interface{}, e error) { return func(context *gin.Context) (i interface{}, e error) {
bReq:=&Course.TopicRequest{} bReq:=&course.TopicRequest{}
err:=context.BindUri(bReq) //使用的是query 参数 err:=context.BindUri(bReq) //使用的是query 参数
if err!=nil{ if err!=nil{
return nil,err return nil,err
......
...@@ -3,7 +3,7 @@ package lib ...@@ -3,7 +3,7 @@ package lib
import ( import (
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"jtthink/framework/gin_" "search_server/framework/gin_"
"net/http" "net/http"
) )
......
...@@ -3,7 +3,7 @@ package gredis ...@@ -3,7 +3,7 @@ package gredis
import ( import (
"encoding/json" "encoding/json"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"jtthink/pkg/config" "search_server/pkg/config"
"time" "time"
) )
......
...@@ -4,8 +4,8 @@ import ( ...@@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql" _ "github.com/jinzhu/gorm/dialects/mysql"
"jtthink/pkg/config" "search_server/pkg/config"
"jtthink/pkg/e" "search_server/pkg/e"
) )
//mysql相关 //mysql相关
......
package Vars package vars
const ( const (
Table_CourseMain="course_main" Table_CourseMain="course_main"
......
::protoc --proto_path=src/protos --micro_out=src/Users --go_out=src/Users Users.proto
protoc --proto_path=src/protos --micro_out=src/Course --go_out=src/Course Course.proto
protoc-go-inject-tag -input=src/Course/Course.pb.go
protoc --proto_path=src/protos --micro_out=src/Course --go_out=src/Course Common.proto
protoc --proto_path=src/protos --micro_out=src/Course --go_out=src/Course CourseTopic.proto
protoc-go-inject-tag -input=src/Course/CourseTopic.pb.go
\ No newline at end of file
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: common.proto
package common
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
timestamp "github.com/golang/protobuf/ptypes/timestamp"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type Timestamp struct {
Timestamp *timestamp.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
Timestr string `protobuf:"bytes,2,opt,name=timestr,proto3" json:"timestr,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Timestamp) Reset() { *m = Timestamp{} }
func (m *Timestamp) String() string { return proto.CompactTextString(m) }
func (*Timestamp) ProtoMessage() {}
func (*Timestamp) Descriptor() ([]byte, []int) {
return fileDescriptor_555bd8c177793206, []int{0}
}
func (m *Timestamp) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Timestamp.Unmarshal(m, b)
}
func (m *Timestamp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Timestamp.Marshal(b, m, deterministic)
}
func (m *Timestamp) XXX_Merge(src proto.Message) {
xxx_messageInfo_Timestamp.Merge(m, src)
}
func (m *Timestamp) XXX_Size() int {
return xxx_messageInfo_Timestamp.Size(m)
}
func (m *Timestamp) XXX_DiscardUnknown() {
xxx_messageInfo_Timestamp.DiscardUnknown(m)
}
var xxx_messageInfo_Timestamp proto.InternalMessageInfo
func (m *Timestamp) GetTimestamp() *timestamp.Timestamp {
if m != nil {
return m.Timestamp
}
return nil
}
func (m *Timestamp) GetTimestr() string {
if m != nil {
return m.Timestr
}
return ""
}
func init() {
proto.RegisterType((*Timestamp)(nil), "common.Timestamp")
}
func init() { proto.RegisterFile("common.proto", fileDescriptor_555bd8c177793206) }
var fileDescriptor_555bd8c177793206 = []byte{
// 121 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x49, 0xce, 0xcf, 0xcd,
0xcd, 0xcf, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0xf0, 0xa4, 0xe4, 0xd3, 0xf3,
0xf3, 0xd3, 0x73, 0x52, 0xf5, 0xc1, 0xa2, 0x49, 0xa5, 0x69, 0xfa, 0x25, 0x99, 0xb9, 0xa9, 0xc5,
0x25, 0x89, 0xb9, 0x05, 0x10, 0x85, 0x4a, 0xf1, 0x5c, 0x9c, 0x21, 0x30, 0x21, 0x21, 0x0b, 0x2e,
0x4e, 0xb8, 0xbc, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x91, 0x94, 0x1e, 0xc4, 0x04, 0x3d, 0x98,
0x09, 0x7a, 0x70, 0xe5, 0x41, 0x08, 0xc5, 0x42, 0x12, 0x5c, 0xec, 0x10, 0x4e, 0x91, 0x04, 0x93,
0x02, 0xa3, 0x06, 0x67, 0x10, 0x8c, 0x9b, 0xc4, 0x06, 0xd6, 0x68, 0x0c, 0x08, 0x00, 0x00, 0xff,
0xff, 0x1b, 0x45, 0x2b, 0x0e, 0xa0, 0x00, 0x00, 0x00,
}
// Code generated by protoc-gen-micro. DO NOT EDIT. // Code generated by protoc-gen-micro. DO NOT EDIT.
// source: Common.proto // source: common.proto
package Course package common
import ( import (
fmt "fmt" fmt "fmt"
......
// Code generated by protoc-gen-micro. DO NOT EDIT. // Code generated by protoc-gen-micro. DO NOT EDIT.
// source: Course.proto // source: course.proto
package Course package course
import ( import (
fmt "fmt" fmt "fmt"
......
// Code generated by protoc-gen-micro. DO NOT EDIT. // Code generated by protoc-gen-micro. DO NOT EDIT.
// source: CourseTopic.proto // source: course_topic.proto
package Course package course
import ( import (
fmt "fmt" fmt "fmt"
......
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: users.proto
package users
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type UserRequest struct {
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *UserRequest) Reset() { *m = UserRequest{} }
func (m *UserRequest) String() string { return proto.CompactTextString(m) }
func (*UserRequest) ProtoMessage() {}
func (*UserRequest) Descriptor() ([]byte, []int) {
return fileDescriptor_030765f334c86cea, []int{0}
}
func (m *UserRequest) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_UserRequest.Unmarshal(m, b)
}
func (m *UserRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_UserRequest.Marshal(b, m, deterministic)
}
func (m *UserRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_UserRequest.Merge(m, src)
}
func (m *UserRequest) XXX_Size() int {
return xxx_messageInfo_UserRequest.Size(m)
}
func (m *UserRequest) XXX_DiscardUnknown() {
xxx_messageInfo_UserRequest.DiscardUnknown(m)
}
var xxx_messageInfo_UserRequest proto.InternalMessageInfo
func (m *UserRequest) GetId() string {
if m != nil {
return m.Id
}
return ""
}
type UserResponse struct {
Ret string `protobuf:"bytes,2,opt,name=ret,proto3" json:"ret,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *UserResponse) Reset() { *m = UserResponse{} }
func (m *UserResponse) String() string { return proto.CompactTextString(m) }
func (*UserResponse) ProtoMessage() {}
func (*UserResponse) Descriptor() ([]byte, []int) {
return fileDescriptor_030765f334c86cea, []int{1}
}
func (m *UserResponse) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_UserResponse.Unmarshal(m, b)
}
func (m *UserResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_UserResponse.Marshal(b, m, deterministic)
}
func (m *UserResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_UserResponse.Merge(m, src)
}
func (m *UserResponse) XXX_Size() int {
return xxx_messageInfo_UserResponse.Size(m)
}
func (m *UserResponse) XXX_DiscardUnknown() {
xxx_messageInfo_UserResponse.DiscardUnknown(m)
}
var xxx_messageInfo_UserResponse proto.InternalMessageInfo
func (m *UserResponse) GetRet() string {
if m != nil {
return m.Ret
}
return ""
}
func init() {
proto.RegisterType((*UserRequest)(nil), "users.UserRequest")
proto.RegisterType((*UserResponse)(nil), "users.UserResponse")
}
func init() { proto.RegisterFile("users.proto", fileDescriptor_030765f334c86cea) }
var fileDescriptor_030765f334c86cea = []byte{
// 134 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2e, 0x2d, 0x4e, 0x2d,
0x2a, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x73, 0x94, 0x64, 0xb9, 0xb8, 0x43,
0x8b, 0x53, 0x8b, 0x82, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 0xf8, 0xb8, 0x98, 0x32, 0x53,
0x24, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0x98, 0x32, 0x53, 0x94, 0x14, 0xb8, 0x78, 0x20, 0xd2,
0xc5, 0x05, 0xf9, 0x79, 0xc5, 0xa9, 0x42, 0x02, 0x5c, 0xcc, 0x45, 0xa9, 0x25, 0x12, 0x4c, 0x60,
0x05, 0x20, 0xa6, 0x91, 0x03, 0xc4, 0x80, 0xe0, 0xd4, 0xa2, 0xb2, 0xcc, 0xe4, 0x54, 0x21, 0x43,
0x2e, 0x96, 0x10, 0x90, 0x41, 0x42, 0x7a, 0x10, 0xcb, 0x90, 0x0c, 0x97, 0x12, 0x46, 0x11, 0x83,
0x98, 0xa8, 0xc4, 0x90, 0xc4, 0x06, 0x76, 0x90, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x35, 0x8a,
0xe3, 0x2d, 0x9f, 0x00, 0x00, 0x00,
}
// Code generated by protoc-gen-micro. DO NOT EDIT. // Code generated by protoc-gen-micro. DO NOT EDIT.
// source: Users.proto // source: users.proto
package Users package users
import ( import (
fmt "fmt" fmt "fmt"
......
syntax = "proto3"; syntax = "proto3";
import "google/protobuf/timestamp.proto"; import "google/protobuf/timestamp.proto";
package Course; package common;
message Timestamp { message Timestamp {
google.protobuf.Timestamp timestamp = 1; google.protobuf.Timestamp timestamp = 1;
string timestr=2; string timestr=2;
......
syntax = "proto3"; syntax = "proto3";
import "Common.proto"; import "common.proto";
package Course; package course;
service CourseService { service CourseService {
...@@ -15,7 +15,7 @@ message CourseModel{ ...@@ -15,7 +15,7 @@ message CourseModel{
float course_price=5; float course_price=5;
float course_price2=6; float course_price2=6;
// @inject_tag: gorm:"type:timestamp" // @inject_tag: gorm:"type:timestamp"
Timestamp addtime=7; common.Timestamp addtime=7;
} }
message ListRequest { message ListRequest {
......
syntax = "proto3"; syntax = "proto3";
import "Common.proto"; import "common.proto";
package Course; package course;
message CourseTopic{ message CourseTopic{
int32 Id=1; int32 Id=1;
int32 CourseId=2; int32 CourseId=2;
...@@ -10,8 +10,8 @@ message CourseTopic{ ...@@ -10,8 +10,8 @@ message CourseTopic{
string Title=6; string Title=6;
string Content=7; string Content=7;
int32 UserId=8; int32 UserId=8;
Timestamp Addtime=9; common.Timestamp Addtime=9;
Timestamp Updatetime=10; common.Timestamp Updatetime=10;
} }
message CourseTopicReply{ message CourseTopicReply{
int32 Id=1; int32 Id=1;
...@@ -20,7 +20,7 @@ message CourseTopicReply{ ...@@ -20,7 +20,7 @@ message CourseTopicReply{
int32 UserId=4; int32 UserId=4;
int32 Likes=5; int32 Likes=5;
int32 Unlikes=6; int32 Unlikes=6;
Timestamp Addtime=7; common.Timestamp Addtime=7;
} }
message TopicRequest{ message TopicRequest{
int32 CourseId=1; int32 CourseId=1;
......
syntax = "proto3"; syntax = "proto3";
package Users; package users;
service UserService { service UserService {
rpc Test(UserRequest) returns (UserResponse) {} rpc Test(UserRequest) returns (UserResponse) {}
......
...@@ -2,32 +2,35 @@ package service ...@@ -2,32 +2,35 @@ package service
import ( import (
"context" "context"
. "jtthink/Course" "search_server/Mapper"
"jtthink/Mapper" . "search_server/protopb/course"
) )
func NewCourseModel(id int32,name string) *CourseModel {
return &CourseModel{CourseId:id,CourseName:name} func NewCourseModel(id int32, name string) *CourseModel {
return &CourseModel{CourseId: id, CourseName: name}
} }
type CourseServiceImpl struct{} type CourseServiceImpl struct{}
func(this *CourseServiceImpl) ListForTop(ctx context.Context, req *ListRequest, rsp *ListResponse) error{
course:=make([]*CourseModel,0) func (this *CourseServiceImpl) ListForTop(ctx context.Context, req *ListRequest, rsp *ListResponse) error {
err:=Mapper.GetCourseListBySql(req.Size).Find(&course).Error course := make([]*CourseModel, 0)
if err!=nil{ err := Mapper.GetCourseListBySql(req.Size).Find(&course).Error
if err != nil {
return err return err
} }
rsp.Result=course rsp.Result = course
return nil return nil
} }
func(this *CourseServiceImpl) GetDetail(ctx context.Context,req *DetailRequest, rsp *DetailResponse) error{ func (this *CourseServiceImpl) GetDetail(ctx context.Context, req *DetailRequest, rsp *DetailResponse) error {
//只取课程详细 //只取课程详细
if req.FetchType==0 || req.FetchType==1 || req.FetchType==3{ if req.FetchType == 0 || req.FetchType == 1 || req.FetchType == 3 {
if err:=Mapper.GetCourseDetail(int(req.CourseId)).Find(rsp.Course).Error;err!=nil{ if err := Mapper.GetCourseDetail(int(req.CourseId)).Find(rsp.Course).Error; err != nil {
return err return err
} }
} }
//只取计数表详细 //只取计数表详细
if req.FetchType==2 || req.FetchType==3{ if req.FetchType == 2 || req.FetchType == 3 {
if err:=Mapper.GetCourseCounts(int(req.CourseId)).Find(&rsp.Counts).Error;err!=nil{ if err := Mapper.GetCourseCounts(int(req.CourseId)).Find(&rsp.Counts).Error; err != nil {
return err return err
} }
} }
......
...@@ -2,13 +2,14 @@ package service ...@@ -2,13 +2,14 @@ package service
import ( import (
"context" "context"
"jtthink/boot" . "search_server/protopb/course"
. "jtthink/Course" "search_server/pkg/mysql"
) )
type CourseTopicServiceImpl struct {} type CourseTopicServiceImpl struct{}
func(this *CourseTopicServiceImpl) GetTopic(ctx context.Context, in *TopicRequest, out *TopicResponse) error{
if err:= boot.GetDB().Table("course_topic").Find(&out.Result).Error;err!=nil { func (this *CourseTopicServiceImpl) GetTopic(ctx context.Context, in *TopicRequest, out *TopicResponse) error {
if err := mysql.GetDB().Table("course_topic").Find(&out.Result).Error; err != nil {
return err return err
} }
return nil return nil
......
...@@ -3,8 +3,8 @@ package main ...@@ -3,8 +3,8 @@ package main
import ( import (
"fmt" "fmt"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"jtthink/boot" "search_server/boot"
"jtthink/pkg/gredis" "search_server/pkg/gredis"
) )
func main() { func main() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment