bookstore.go 596 B

12345678910111213141516171819202122232425262728293031
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "bookstore/api/internal/config"
  6. "bookstore/api/internal/handler"
  7. "bookstore/api/internal/svc"
  8. "github.com/tal-tech/go-zero/core/conf"
  9. "github.com/tal-tech/go-zero/rest"
  10. )
  11. var configFile = flag.String("f", "etc/bookstore-api.yaml", "the config file")
  12. func main() {
  13. flag.Parse()
  14. var c config.Config
  15. conf.MustLoad(*configFile, &c)
  16. ctx := svc.NewServiceContext(c)
  17. server := rest.MustNewServer(c.RestConf)
  18. defer server.Stop()
  19. handler.RegisterHandlers(server, ctx)
  20. fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
  21. server.Start()
  22. }