http

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Cmd = &cobra.Command{
		Use:           "http",
		Short:         "HTTP API daemon",
		SilenceUsage:  true,
		SilenceErrors: true,
		Run: func(_ *cobra.Command, _ []string) {
			var (
				sHttp     *http.HTTP
				sMicro    *micro.Micro
				c         func()
				e         error
				ctxAll    context.Context
				ctxCancel context.CancelFunc
			)
			defer func() {
				if c != nil {
					c()
				}
			}()
			cmd.Slave.Executor(func(ctx context.Context) error {
				initial, _ := entrypoint.CtxExtractInitial(ctx)
				ctxAll, ctxCancel = context.WithCancel(ctx)
				sHttp, c, e = daemon.BuildHTTP(ctxAll, initial, cmd.Observer)
				if e != nil {
					return e
				}
				sMicro, c, e = daemon.BuildMicro(ctxAll, initial, cmd.Observer)
				if e != nil {
					return e
				}
				return nil
			}, func(ctx context.Context) error {
				var wg sync.WaitGroup
				wg.Add(2)
				go func() {
					if err := sHttp.ListenAndServe(); err != nil {
						e = err
						ctxCancel()
					}
					wg.Done()
				}()
				go func() {
					if err := sMicro.ListenAndServe(); err != nil {
						e = err
						ctxCancel()
					}
					wg.Done()
				}()
				wg.Wait()
				return e
			})
		},
	}
)

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