go-zero/example/bookstore/api/bookstore.go
2020-09-16 13:27:16 +08:00

32 lines
596 B
Go

package main
import (
"flag"
"fmt"
"bookstore/api/internal/config"
"bookstore/api/internal/handler"
"bookstore/api/internal/svc"
"github.com/tal-tech/go-zero/core/conf"
"github.com/tal-tech/go-zero/rest"
)
var configFile = flag.String("f", "etc/bookstore-api.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
ctx := svc.NewServiceContext(c)
server := rest.MustNewServer(c.RestConf)
defer server.Stop()
handler.RegisterHandlers(server, ctx)
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
server.Start()
}