service_wrapper

package
v0.0.0-...-26b160e Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

@Time : 2019/5/13 10:37 @Author : kenny zhu @File : options.go @Software: GoLand @Others:

@Time : 2019/5/13 10:46 @Author : kenny zhu @File : service.go @Software: GoLand @Others:

@Time : 2019/5/13 10:36 @Author : kenny zhu @File : wrapper.go @Software: GoLand @Others:

Index

Constants

This section is empty.

Variables

View Source
var (
	// For serving
	DefaultName    = "gin-web"
	DefaultVersion = "latest"
	DefaultId      = uuid.New().String()
	DefaultAddress = ":0"

	// for registration
	DefaultRegisterTTL      = time.Minute
	DefaultRegisterInterval = time.Second * 30
)

Functions

This section is empty.

Types

type Option

type Option func(o *Options)

func Address

func Address(a string) Option

Address to bind to - host:port

func Advertise(a string) Option

The address to advertise for discovery - host:port

func Context

func Context(ctx context.Context) Option

Context specifies a context for the service. Can be used to signal shutdown of the service. Can be used for extra option values.

func Description

func Description(a string) Option

func Engine

func Engine(g *gin.Engine) Option

func Id

func Id(id string) Option

Unique server id

func Metadata

func Metadata(md map[string]string) Option

Metadata associated with the service

func Name

func Name(n string) Option

Server name

func RegisterInterval

func RegisterInterval(t time.Duration) Option

func RegisterTTL

func RegisterTTL(t time.Duration) Option

func Registry

func Registry(r registry.Registry) Option

func Secure

func Secure(b bool) Option

Secure Use secure communication. If TLSConfig is not specified we use InsecureSkipVerify and generate a self signed cert

func ServiceInfo

func ServiceInfo(s *registry.Service) Option

func TLSConfig

func TLSConfig(t TLSFile) Option

TLSConfig to be used for the transport.

func Version

func Version(v string) Option

Version of the service

type Options

type Options struct {
	Address   string
	Advertise string

	// service
	Name        string
	Version     string
	Id          string
	Metadata    map[string]string
	Description string

	// or service struct directly..
	ServiceInfo *registry.Service

	Registry         registry.Registry
	RegisterTTL      time.Duration
	RegisterInterval time.Duration

	// define gin.Engine
	Engine *gin.Engine

	// https config
	Secure    bool
	TLSConfig TLSFile

	// Alternative Options
	Context context.Context
}

type Runner

type Runner func(addr ...string) (err error)

type Service

type Service interface {
	Client(opts ...web.Option) *http.Client
	Options() Options
	Run() error
}

Service is a web service with service discovery built in

func NewService

func NewService(opts ...Option) Service

NewService returns a new web.ServiceWrapper, for future use service for extend.

type TLSFile

type TLSFile struct {
	CertFile string
	KeyFile  string
}

Jump to

Keyboard shortcuts

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