frontend

package
v0.0.0-...-b36981d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RunCmd = &cobra.Command{
	Use:   "frontend",
	Short: "",
	Long:  ``,
	Run: func(cmd *cobra.Command, args []string) {
		defer log.Flush()
		defer func() {
			if r := recover(); r != nil {

				err, ok := r.(error)
				if !ok {
					err = fmt.Errorf("unknown error: %v", r)
				}

				log.Err(err).Panic("unknown error")
			}
		}()

		config.EnvPrefix = "STARTER"
		cfg := config.New("app.yml")
		err := initialize(cfg)
		if err != nil {
			log.Panicf("main: frontend initialize failed: %v", err)
			return
		}

		fn := cfg.InitTracer("frontend")
		defer fn()

		nap := gql.NewHTTPServer(_eventClient, _walletClient, _temporalClient)
		httpServer := &http.Server{
			Addr:    cfg.Frontend.HTTPBind,
			Handler: nap,
		}

		go func() {

			log.Infof("frontend is serving HTTP on %s\n", httpServer.Addr)
			err := httpServer.ListenAndServe()
			if err != nil {
				log.Errorf("main: http server listen failed: %v\n", err)
			}
		}()

		stopChan := make(chan os.Signal, 1)
		signal.Notify(stopChan, syscall.SIGINT, syscall.SIGKILL, syscall.SIGHUP, syscall.SIGTERM)
		<-stopChan
		log.Info("main: shutting down server...")

		ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
		defer cancel()
		if err := httpServer.Shutdown(ctx); err != nil {
			log.Errorf("main: http server shutdown error: %v", err)
		} else {
			log.Info("main: gracefully stopped")
		}

	},
}

RunCmd 是 frontend service 的進入口

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL