frontend

package
v0.0.0-...-90b204c Latest Latest
Warning

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

Go to latest
Published: Nov 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
		}

		tp, err := cfg.TracerProvider("frontend")
		ctx, cancel := context.WithCancel(context.Background())
		defer cancel()

		defer func(ctx context.Context) {

			ctx, cancel = context.WithTimeout(ctx, time.Second*5)
			defer cancel()
			if err := tp.Shutdown(ctx); err != nil {
				log.Err(err).Panic("tp shutdown failed")
			}
		}(ctx)

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

		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(ctx, 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