package main import ( "flag" "github.com/go-kratos/kratos-layout/internal/conf" "github.com/go-kratos/kratos/v2" "github.com/go-kratos/kratos/v2/log" "github.com/go-kratos/kratos/v2/middleware/tracing" "github.com/go-kratos/kratos/v2/transport/grpc" "github.com/go-kratos/kratos/v2/transport/http" "os" ) // go build -ldflags "-X main.Version=x.y.z" var ( // Name is the name of the compiled software. Name string // Version is the version of the compiled software. Version string // flagconf is the config flag. flagconf string id, _ = os.Hostname() ) func init() { flag.StringVar(&flagconf, "conf", "", "config file, eg: -conf config.yaml") } func newApp(hs *http.Server, gs *grpc.Server) *kratos.App { return kratos.New( kratos.ID(id), kratos.Name(Name), kratos.Version(Version), kratos.Metadata(map[string]string{}), kratos.Server( hs, gs, ), ) } func main() { flag.Parse() var c conf.Config conf.LoadFromYaml(flagconf, &c) logger := log.With(log.NewStdLogger(os.Stdout), "ts", log.DefaultTimestamp, "caller", log.DefaultCaller, "service.id", id, "service.name", Name, "service.version", Version, "trace.id", tracing.TraceID(), "span.id", tracing.SpanID(), ) log.SetLogger(logger) app, cleanup, err := wireApp(c.Server, c.Data) if err != nil { panic(err) } defer cleanup() // start and wait for stop signal if err := app.Run(); err != nil { panic(err) } }