main.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. _ "github.com/go-nunu/nunu-layout-advanced/pkg/validation" // 匿名导入以激活自定义校验器
  7. "github.com/go-nunu/nunu-layout-advanced/cmd/server/wire"
  8. "github.com/go-nunu/nunu-layout-advanced/pkg/config"
  9. "github.com/go-nunu/nunu-layout-advanced/pkg/log"
  10. "go.uber.org/zap"
  11. )
  12. // @title Nunu Example API
  13. // @version 1.0.0
  14. // @description This is a sample server celler server.
  15. // @termsOfService http://swagger.io/terms/
  16. // @contact.name API Support
  17. // @contact.url http://www.swagger.io/support
  18. // @contact.email support@swagger.io
  19. // @license.name Apache 2.0
  20. // @license.url http://www.apache.org/licenses/LICENSE-2.0.html
  21. // @host localhost:8000
  22. // @securityDefinitions.apiKey Bearer
  23. // @in header
  24. // @name Authorization
  25. // @externalDocs.description OpenAPI
  26. // @externalDocs.url https://swagger.io/resources/open-api/
  27. func main() {
  28. var envConf = flag.String("conf", "config/local.yml", "config path, eg: -conf ./config/local.yml")
  29. flag.Parse()
  30. conf := config.NewConfig(*envConf)
  31. // 检查是否有环境变量指定服务类型
  32. serviceType := log.API
  33. logger := log.NewServiceLog(conf, serviceType)
  34. app, cleanup, err := wire.NewWire(conf, logger)
  35. defer cleanup()
  36. if err != nil {
  37. panic(err)
  38. }
  39. logger.Info("server start", zap.String("host", fmt.Sprintf("http://%s:%d", conf.GetString("http.host"), conf.GetInt("http.port"))))
  40. logger.Info("docs addr", zap.String("addr", fmt.Sprintf("http://%s:%d/swagger/index.html", conf.GetString("http.host"), conf.GetInt("http.port"))))
  41. if err = app.Run(context.Background()); err != nil {
  42. panic(err)
  43. }
  44. }