goservice

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2022 License: BSD-2-Clause Imports: 13 Imported by: 0

README

Go SDK

A framework for Golang Microservices

Author: Viet Tran viettranx@gmail.com

Copyright: 2022 Le Quoc Binh lequocbinh.contact@gmail.com

Documentation

Index

Constants

View Source
const (
	DevEnv     = "dev"
	StgEnv     = "stg"
	PrdEnv     = "prd"
	DefaultEnv = DevEnv
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppFlagSet

type AppFlagSet struct {
	*flag.FlagSet
}

func (*AppFlagSet) GetSampleEnvs

func (f *AppFlagSet) GetSampleEnvs()

func (*AppFlagSet) Parse

func (f *AppFlagSet) Parse(args []string)

type Function

type Function func(ServiceContext) error

A kind of server job

type HasPrefix

type HasPrefix interface {
	GetPrefix() string
	Get() interface{}
}

type HttpServer

type HttpServer interface {
	Runnable
	// Add handlers to GIN
	AddHandler(HttpServerHandler)
	// Return server config
	//GetConfig() http_server.Config
	// URI that the server is listening
	URI() string
}

GIN HTTP server for REST API

type HttpServerHandler

type HttpServerHandler = func(*gin.Engine)

HTTP Server Handler for register some routes and gin handlers

type Option

type Option func(*service)

Convenience option method for creating/initializing a service

func WithFileLogger

func WithFileLogger() Option

Service will write log data to file with this option

func WithInitRunnable

func WithInitRunnable(r PrefixRunnable) Option

Add init component to SDK These components will run sequentially before service run

func WithName

func WithName(name string) Option

WithName Service must have a name for service discovery and logging/monitoring

func WithRunnable

func WithRunnable(r Runnable) Option

Add Runnable component to SDK These components will run parallel in when service run

func WithSentryDsn added in v1.0.2

func WithSentryDsn(dsn string) Option

func WithVersion

func WithVersion(version string) Option

WithVersion Every deployment needs a specific version

type PrefixRunnable

type PrefixRunnable interface {
	HasPrefix
	Runnable
}

type Runnable

type Runnable interface {
	Name() string
	InitFlags()
	Configure() error
	Run() error
	Stop() <-chan bool
}

Runnable is an abstract object in SDK Almost components are Runnable. SDK will manage their lifecycle InitFlags -> Configure -> Run -> Stop

type Service

type Service interface {
	// A part of Service, it's passed to all handlers/functions
	ServiceContext
	// Name of the service
	Name() string
	// Version of the service
	Version() string
	// Gin HTTP Server wrapper
	HTTPServer() HttpServer
	// Init with options, they can be db connections or
	// anything the service need handle before starting
	Init() error
	// Same Init but have prefix
	InitPrefix(prefix ...string) error
	// This method returns service if it is registered on discovery
	IsRegistered() bool
	// Start service and its all component.
	// It will be stopped if any service return error
	Start() error
	// Stop service and its all component.
	Stop()
	// Method export all flags to std/terminal
	// We might use: "> .env" to move its content .env file
	OutEnv()

	// Method to add some Runable into it
	Add(opts ...Option) Service
}

The heart of SDK, Service represents for a real micro service with its all components

func New

func New(opts ...Option) Service

type ServiceContext

type ServiceContext interface {
	// Logger for a specific service, usually it has a prefix to distinguish
	// with each others
	Logger(prefix string) logger.Logger
	// Get component with prefix
	Get(prefix string) (interface{}, bool)
	MustGet(prefix string) interface{}
	Env() string
}

Service Context: A wrapper for all things needed for developing a service

type Storage

type Storage interface {
	Get(prefix string) (interface{}, bool)
	MustGet(prefix string) interface{}
}

The storage store all db connection in service

Directories

Path Synopsis
examples
aws
fcm
Logging provider
Logging provider
aws
----------------------------------------------------------------*\
----------------------------------------------------------------*\
fcm
----------------------------------------------------------------*\
----------------------------------------------------------------*\
util

Jump to

Keyboard shortcuts

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