package main import ( "context" "fmt" "net/http" "os" "git.chuangxin1.com/csacred/toolkit" "github.com/chuangxin1/httprouter" "github.com/go-kit/kit/log" users "git.chuangxin1.com/csacred/toolkit/example/cuser/service" ) func genUserHandlers( ctx context.Context, router *httprouter.Router, options toolkit.ServiceOptions, logger log.Logger) { ver := "v1" tags := []string{ver} passingOnly := true name := users.ServiceName instancer, err := toolkit.NewConsulInstancer( options, name, tags, passingOnly, logger) if err != nil { fmt.Println("NewConsulInstancer", err.Error()) os.Exit(0) } handers := users.GenGatewayHandlers(ctx, instancer, logger) prefix := "/api/" + name + "/" + ver //ctx = context.WithValue(ctx, contextKeyPrefix, prefix) for i := range handers { fmt.Println(handers[i].Method, prefix+handers[i].Router) hander := handers[i].Hander router.Handle( handers[i].Method, prefix+handers[i].Router, func(w http.ResponseWriter, req *http.Request) { req = req.WithContext(context.WithValue( req.Context(), toolkit.ContextKeyGateWayPrefix, prefix)) hander.ServeHTTP(w, req) }) //handers[i].Hander) } }