Commit 81d98087 by huangchengyi

1.0

parent 59acfdf8
package main
import (
_ "goods_machining/controller"
)
func main() {
//
//var path string
//flag.StringVar(&path, "config", "conf/config.ini", "配置文件")
//flag.Parse()
//if err := boot.Boot(path); err != nil {
// log.Println(err)
//}
//
//r := gin.New()
//gin_.BootStrap(r)
//
//c:=grpc.NewClient()
//r:=gin.New()
//r.Handle("GET","/test", func(ctx *gin.Context) {
// news
// c:=Course.NewCourseService("api.jtthink.com.course",c)
// course_rsp,_:=c.ListForTop(context.Background(),&Course.ListRequest{Size:10})
// ctx.JSON(200,gin.H{"Result":course_rsp.Result})
//})
//service:=web.NewService(
// web.Name("api.jtthink.com.http.course"),
// web.Handler(r),
//)
//
//
//
//port := config.Get("web.port").String()
////web改成micro 就是grpc,并直接注册到etcd里面
//service := web.NewService(
// web.Name("go.micro.api.http.course"),
// web.Handler(r),
// web.Address(":"+port),
//)
//
//if err := service.Init(); err != nil {
// log.Println(err)
//}
//if err := service.Run(); err != nil {
// log.Println(err)
//}
}
package main
import (
"context"
"github.com/micro/go-micro/v2/client/grpc"
"github.com/micro/go-micro/v2/web"
"goods_machining/Course"
"log"
"net/http"
)
func main() {
service:=web.NewService(
web.Name("api.jtthink.com.http.course"))
c:=grpc.NewClient()
service.HandleFunc("/test", func(writer http.ResponseWriter, request *http.Request) {
c:=Course.NewCourseService("go.micro.api.jtthink.course",c)
course_rsp,_:=c.ListForTop(context.Background(),&Course.ListRequest{Size:10})
log.Println(course_rsp.Result)
writer.Write([]byte("http api test"))
})
service.Init()
if err:= service.Run(); err != nil {
log.Println(err)
}
}
\ No newline at end of file
package main
import (
"github.com/micro/go-micro/v2"
"goods_machining/protopb/course"
"goods_machining/service"
"log"
)
func main() {
cService:=micro.NewService(
micro.Name("go.micro.api.jtthink.course"))
cService.Init()
err:=course.RegisterCourseServiceHandler(cService.Server(),service.NewCourseServiceImpl())
if err!=nil{
log.Fatal(err)
}
if err = cService.Run(); err != nil {
log.Println(err)
}
}
\ No newline at end of file
package main
import (
"context"
"github.com/micro/go-micro/v2/client"
"goods_machining/protopb/course"
"github.com/micro/go-micro/v2"
"goods_machining/protopb/users"
"log"
)
type UserService struct{
client client.Client
}
func (this *UserService) Test(ctx context.Context, req *users.UserRequest, rsp *users.UserResponse) error {
rsp.Ret="users"+req.Id
c:=course.NewCourseService("go.micro.api.jtthink.course",this.client)
course_rsp,_:=c.ListForTop(ctx,&course.ListRequest{Size:10})
log.Println(course_rsp.Result)
return nil
}
func NewUserService(c client.Client) *UserService {
return &UserService{client:c}
}
func main() {
service:=micro.NewService(
micro.Name("go.micro.api.jtthink.user"))
service.Init()
err:=users.RegisterUserServiceHandler(service.Server(),NewUserService(service.Client()))
if err!=nil{
log.Fatal(err)
}
if err = service.Run(); err != nil {
log.Println(err)
}
}
## 搜索服务
## golang 商品微服务
### 项目启动
直接到cmd下面直接找到想启动的服务进行```go run xxx```即可,需要传入配置文件地址的话,则可以
......
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