求解:go程序能在liteide中运行,但再GoLand中运行就会出项如下错误command-line-arguments user\main.go:112:10: undefined: UserService

Choxsan · · 2391 次点击 · 开始浏览    置顶
这是一个创建于 的主题,其中的信息可能已经有所发展或是发生改变。

主程序: package main import ( "context" "flag" "net/http" "os" "mtcomm/db/mysql" "mtcomm/db/redis" logger "mtcomm/log" stdprometheus "github.com/prometheus/client_golang/prometheus" "github.com/tjz101/goprop" kitprometheus "github.com/go-kit/kit/metrics/prometheus" "github.com/go-kit/kit/tracing/opentracing" httptransport "github.com/go-kit/kit/transport/http" stdopentracing "github.com/opentracing/opentracing-go" zipkin "github.com/openzipkin/zipkin-go-opentracing" ) var ( namespace string serviceName string mysqlClient mysql.MysqlClient redisClient redis.RedisClient tracer stdopentracing.Tracer prop *goprop.Prop log *logger.Logger ) func init() { /* init properties */ propFile := flag.String("prop", "prop.properties", "properties file") flag.Parse() prop = goprop.NewProp() prop.Read(*propFile) namespace = prop.Get("namespace") //kubernetes namespace serviceName = prop.Get("serviceName") //kubernetes service name /* init log */ logger.SetDefaultLogLevel(logger.LevelDebug) logger.With("serviceName", serviceName) log = logger.GetDefaultLogger() /* init mysql */ mysqlClient = mysql.NewMysqlClient(&mysql.MysqlInfo{ UserName: prop.Get("mysql_username"), Password: prop.Get("mysql_password"), IP: prop.Get("mysql_ip"), Port: prop.Get("mysql_port"), DatabaseName: prop.Get("mysql_database"), Logger: logger.GetDefaultLogger(), }) /* init redis */ redisClient = redis.NewRedisClient(&redis.RedisServerInfo{ Ctx: context.TODO(), Logger: logger.GetDefaultLogger(), RedisHost: prop.Get("redis_host"), }) } func main() { // init zipkinAddr := prop.Get("zipkinAddr") listenPort := prop.Get("listenPort") options := []httptransport.ServerOption{ httptransport.ServerErrorLogger(*logger.GetDefaultLogger().GetDefaultKitLogger()), } // init tracing domain. { if zipkinAddr != "" { logger.Info("tracer", "Zipkin", "zipkinAddr", zipkinAddr) collector, err := zipkin.NewHTTPCollector(zipkinAddr, zipkin.HTTPBatchSize(1)) if err != nil { logger.Error("tracer", "Zipkin", "err", err) os.Exit(1) } tracer, err = zipkin.NewTracer( zipkin.NewRecorder(collector, false, listenPort, serviceName), ) if err != nil { logger.Error("tracer", "Zipkin", "err", err) os.Exit(1) } } else { logger.Info("tracer", "none") tracer = stdopentracing.GlobalTracer() // no-op } } fieldKeys := []string{"method", "error"} requestCount := kitprometheus.NewCounterFrom(stdprometheus.CounterOpts{ Namespace: namespace, Subsystem: serviceName, Name: "request_count", Help: "Number of requests received.", }, fieldKeys) requestLatency := kitprometheus.NewSummaryFrom(stdprometheus.SummaryOpts{ Namespace: namespace, Subsystem: serviceName, Name: "request_latency_microseconds", Help: "Total duration of requests in microseconds.", }, fieldKeys) /* create service */ var svc UserService svc = userService{} svc = loggingMiddleware{svc} svc = instrumentingMiddleware{requestCount, requestLatency, svc} // 保存请求 saveUserHandler := httptransport.NewServer( opentracing.TraceServer(tracer, "SaveUser")(makeSaveUserEndpoint(svc)), decodeSaveUserRequest, encodeResponse, append(options, httptransport.ServerBefore(opentracing.HTTPToContext(tracer, "SaveUser", *logger.GetDefaultLogger().GetDefaultKitLogger())))..., ) // 删除请求 delUserHandler := httptransport.NewServer( opentracing.TraceServer(tracer, "DelUser")(makeDelUserEndpoint(svc)), decodeDelUserRequest, encodeResponse, append(options, httptransport.ServerBefore(opentracing.HTTPToContext(tracer, "DelUser", *logger.GetDefaultLogger().GetDefaultKitLogger())))..., ) // 修改请求 updateUserHandler := httptransport.NewServer( opentracing.TraceServer(tracer, "UpdateUser")(makeUpdateUserEndpoint(svc)), decodeUpdateUserRequest, encodeResponse, append(options, httptransport.ServerBefore(opentracing.HTTPToContext(tracer, "UpdateUser", *logger.GetDefaultLogger().GetDefaultKitLogger())))..., ) // 查询请求 selectAllUserHandler := httptransport.NewServer( opentracing.TraceServer(tracer, "SelectAllUser")(makeSelectAllUserEndpoint(svc)), decodeSelectAllUserRequest, encodeResponse, append(options, httptransport.ServerBefore(opentracing.HTTPToContext(tracer, "SelectAllUser", *logger.GetDefaultLogger().GetDefaultKitLogger())))..., ) http.Handle("/saveUser", saveUserHandler) http.Handle("/delUser", delUserHandler) http.Handle("/updateUser", updateUserHandler) http.Handle("/selectAllUser", selectAllUserHandler) http.Handle("/metrics", stdprometheus.Handler()) logger.Info("msg", "HTTP", "addr", listenPort) logger.Info("err", http.ListenAndServe(listenPort, nil)) } 错误信息: GOROOT=C:\Go #gosetup GOPATH=C:\gowork #gosetup C:\Go\bin\go.exe build -i -o C:\Users\123\AppData\Local\Temp\___go_build_main_go.exe C:/gowork/src/user/main.go #gosetup # command-line-arguments user\main.go:112:10: undefined: UserService user\main.go:113:8: undefined: userService user\main.go:114:8: undefined: loggingMiddleware user\main.go:115:8: undefined: instrumentingMiddleware user\main.go:119:47: undefined: makeSaveUserEndpoint user\main.go:120:3: undefined: decodeSaveUserRequest user\main.go:121:3: undefined: encodeResponse user\main.go:127:46: undefined: makeDelUserEndpoint user\main.go:128:3: undefined: decodeDelUserRequest user\main.go:129:3: undefined: encodeResponse user\main.go:129:3: too many errors

有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

2391 次点击  
加入收藏 微博
2 回复  |  直到 2018-04-06 14:27:04
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传