rock

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrNameApplicationInitFailure = "rock.Application.InitFailure"
	ErrNameUnsupportedFormat      = "unsupported format"
)
View Source
const ConfigFilename = "rockgo"

Variables

This section is empty.

Functions

func Config

func Config() *sync.Map

Get shared configs

func ConfigIn

func ConfigIn(keyPath string) interface{}

Find value from shared configs with <keyPath> delimited by ".".

func ImportConfigFilesFromDirectory

func ImportConfigFilesFromDirectory(dir string) error

Load each file in the <dir> without recursive by ImportConfigFromPaths(). Contents of file would be stored in shared config with filename (without extension). e.g. app.yaml would use "app" as key. - Return: each got error

func ImportConfigFromPaths

func ImportConfigFromPaths(paths ...string) error

ImportConfigFromPaths load multiple config files. And then store in a shared map with key by filename (stripped ext), e.g. abc for abc.json. - Parameters:

  • paths: Path list to be loaded, empty string would be ignored.

- Return: each got error

func LoadConfigFromFile

func LoadConfigFromFile(path string, into interface{}) (err error)

LoadConfigFromFile support json and yaml format with extension (json/yaml/yml)

func Logger

func Logger(name string) *log.Logger

Logger would return initialized logger with <name> from rock config, you should call it after NewApplication. - Return: Named logger, or default logger.

func Metric

func Metric() *statsd.Client

Metric pass statsd client to make custom record.

- Return: may be nil if not calling rock.Application#InitWithConfig() or not configure correctly.

func MetricCount

func MetricCount(key string, num interface{})

MetricCount would change count on <num> for key.

func MetricDecrease

func MetricDecrease(key string)

MetricDecrease would decrease count on 1 for key with statsd count.

func MetricGauge

func MetricGauge(bucket string, value interface{})

func MetricHistogram

func MetricHistogram(bucket string, value interface{})

func MetricIncrease

func MetricIncrease(key string)

MetricIncrease would increase count on 1 for key with statsd count.

func MetricTimeDuration added in v0.2.1

func MetricTimeDuration(key string, duration time.Duration)

MetricTimeDuration would record time duration for key with statsd timing.

- Parameters:

  • duration: e.g. time.Now().Sub(oldTime) or time.Second * 4

func MetricTiming

func MetricTiming(key string, value interface{})

Types

type Application

type Application interface {
	// Name returns app_name in rockgo config.
	Name() string

	// Iris returns iris application.
	Iris() *iris.Application

	// Set panic handler, it would working on sentry.repanic is true only.
	SetPanicHandler(fn PanicHandler)

	// Serve make Service to register handler.
	//
	// - Parameters:
	//   - name: for statsd
	//   - path: path from root, e.g. "foo" for "/foo"
	Serve(name, path string) *Service

	// ServeGroup make ServiceGroup to handle multiple Services like directory.
	//
	// - Parameters:
	//   - name: for statsd
	//   - path: directory name in path from root
	ServeGroup(name, path string) *ServiceGroup

	// Run server with <host> and multiple [conf].
	//
	// - Parameters:
	//   - host: [server name] with port. e.g. "mydomain.com:80" or ":8080" (equal "0.0.0.0:8080")
	Run(host string, conf ...host.Configurator) error
}

func NewApplication

func NewApplication(configDir string) (Application, error)

NewApplication would load config files from <configDir>, and then make Application with rockgo.yaml (or json) in <configDir>.

type PanicHandler

type PanicHandler func(ctx iris.Context, err error)

type Service

type Service struct {
	// contains filtered or unexported fields
}

func (*Service) Connect

func (s *Service) Connect(fn ...iris.Handler) *Service

func (*Service) Delete

func (s *Service) Delete(fn ...iris.Handler) *Service

func (*Service) Get

func (s *Service) Get(fn ...iris.Handler) *Service

func (*Service) HandleDir

func (s *Service) HandleDir(dir string, opts ...router.DirOptions)

HandleDir would serve static files. - Parameters:

  • dir: Directory path

func (*Service) Head

func (s *Service) Head(fn ...iris.Handler) *Service

func (*Service) Option

func (s *Service) Option(fn ...iris.Handler) *Service

func (*Service) Patch

func (s *Service) Patch(fn ...iris.Handler) *Service

func (*Service) Post

func (s *Service) Post(fn ...iris.Handler) *Service

func (*Service) Put

func (s *Service) Put(fn ...iris.Handler) *Service

func (*Service) Trace

func (s *Service) Trace(fn ...iris.Handler) *Service

type ServiceGroup

type ServiceGroup struct {
	// contains filtered or unexported fields
}

func (*ServiceGroup) Serve

func (g *ServiceGroup) Serve(name, path string) *Service

func (*ServiceGroup) ServeGroup

func (g *ServiceGroup) ServeGroup(name, path string) *ServiceGroup

func (*ServiceGroup) Use

func (g *ServiceGroup) Use(mw ...iris.Handler) *ServiceGroup

Use middlewares into application or party.

Jump to

Keyboard shortcuts

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