goservice

package module
v0.0.0-...-3f22ba1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: MIT Imports: 21 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Go Service Framework

Go service is a microservice framework in golang

Documentation

Index

Constants

View Source
const GO_SERVICE_PREFIX = "GS"
View Source
const GO_SERVICE_VERSION = "1.0.0"
View Source
const (
	MCountCall string = "count_call"
)
View Source
const (
	MCountCallTime string = "1h1h"
)

Variables

This section is empty.

Functions

func DeSerializerJson

func DeSerializerJson(jsonString string) (interface{}, error)

func MetricsGetValueCounter

func MetricsGetValueCounter(m metric.Metric) float64

func SerializerJson

func SerializerJson(data interface{}) (string, error)

Types

type Action

type Action struct {
	Name   string
	Params interface{}
	Rest   Rest
	Handle func(*Context) (interface{}, error)
}

type Broker

type Broker struct {
	Config   BrokerConfig
	Services []*Service
	Started  func(*Context)
	Stoped   func(*Context)
	// contains filtered or unexported fields
}

func Init

func Init(config BrokerConfig) *Broker

func (*Broker) Call

func (b *Broker) Call(callerService string, traceName string, action string, params interface{}, opts CallOpts) (interface{}, error)

func (*Broker) Hold

func (b *Broker) Hold()

func (*Broker) LoadService

func (b *Broker) LoadService(service *Service)

func (*Broker) LogError

func (b *Broker) LogError(message string)

func (*Broker) LogInfo

func (b *Broker) LogInfo(message string)

extenal console

func (*Broker) LogWarning

func (b *Broker) LogWarning(message string)

type BrokerConfig

type BrokerConfig struct {
	NodeId            string
	TransporterConfig TransporterConfig
	LoggerConfig      Logconfig
	Metrics           string
	TraceConfig       TraceConfig
	DiscoveryConfig   DiscoveryConfig
	RequestTimeOut    int
}

BROKER

type Call

type Call func(action string, params interface{}, opts ...CallOpts) (interface{}, error)

type CallOpts

type CallOpts struct {
}

type Context

type Context struct {
	RequestId         string
	TraceParentId     string
	TraceParentRootId string
	ResponseId        string
	Params            interface{}
	Meta              interface{}
	FromService       string
	FromAction        string
	FromEvent         string
	FromNode          string
	CallingLevel      int
	Call              Call
	Service           *Service
}

func (*Context) LogError

func (c *Context) LogError(message string)

func (*Context) LogInfo

func (c *Context) LogInfo(message string)

func (*Context) LogWarning

func (c *Context) LogWarning(message string)

type Count

type Count struct {
	Interval int           `json:"interval"`
	Samples  []CountSample `json:"samples"`
}

type CountSample

type CountSample struct {
	Type  string  `json:"type"`
	Count float64 `json:"count"`
}

type DiscoveryBroadcastsChannelType

type DiscoveryBroadcastsChannelType string
const (
	DiscoveryBroadcasts           DiscoveryBroadcastsChannelType = "DISCOVERY"
	DiscoveryBroadcastsInfo       DiscoveryBroadcastsChannelType = "INFO"
	DiscoveryBroadcastsHeartbeat  DiscoveryBroadcastsChannelType = "HEART_BEAT"
	DiscoveryBroadcastsPing       DiscoveryBroadcastsChannelType = "PING"
	DiscoveryBroadcastsPong       DiscoveryBroadcastsChannelType = "PONG"
	DiscoveryBroadcastsDisconnect DiscoveryBroadcastsChannelType = "DISCONNECT"
)

type DiscoveryConfig

type DiscoveryConfig struct {
	Enable                   bool
	HeartbeatInterval        int
	HeartbeatTimeout         int
	CleanOfflineNodesTimeout int
	Config                   interface{}
	DiscoveryType            DiscoveryType
}

type DiscoveryPotocol

type DiscoveryPotocol int
const (
	TopicDiscover DiscoveryPotocol = iota + 1
	TopicInfo
	TopicHeartbeat
	TopicPing
	TopicPong
	TopicDisconnect
)

type DiscoveryRedisConfig

type DiscoveryRedisConfig struct {
	Port     int
	Host     string
	Password string
	Db       int
}

type DiscoveryType

type DiscoveryType int

DISCOVERY & REGISTRY

const (
	DiscoveryTypeRedis DiscoveryType = iota + 1
)

type Event

type Event struct {
	Name   string
	Params interface{}
	Handle func(*Context)
}

type EventBus

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

func (*EventBus) Publish

func (eb *EventBus) Publish(channel string, data interface{})

func (*EventBus) Subscribe

func (eb *EventBus) Subscribe(channel string, fn interface{})

func (*EventBus) UnSubscribe

func (eb *EventBus) UnSubscribe(channel string)

type EventBusData

type EventBusData struct {
	Channel string
	Handle  []reflect.Value
}

type Gateway

type Gateway struct {
	Gin       *gin.Engine
	GinRoutes []*gin.RouterGroup
	Services  []RegistryService

	Config  GatewayConfig
	Service *Service
	// contains filtered or unexported fields
}

func (*Gateway) MapServices

func (g *Gateway) MapServices()

type GatewayConfig

type GatewayConfig struct {
	Name   string
	Host   string
	Port   int
	Routes []GatewayConfigRoute
}

type GatewayConfigRoute

type GatewayConfigRoute struct {
	Path             string
	WhileList        []string
	StaticPath       string
	StaticFolderRoot string
}

type Log

type Log struct {
	Config  Logconfig
	Extenal interface{}
}

type LogData

type LogData struct {
	Type    LogType
	Message string
	Payload map[string]interface{}
	Time    int
}

type LogExternal

type LogExternal int
const (
	LogConsole LogExternal = iota + 1
	LogFile
)

type LogType

type LogType int
const (
	LogTypeInfo LogType = iota + 1
	LogTypeWarning
	LogTypeError
)

type Logconfig

type Logconfig struct {
	Enable   bool
	Type     LogExternal
	LogLevel LogType
}

type LoggerConsole

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

func (*LoggerConsole) Start

func (l *LoggerConsole) Start()

func (*LoggerConsole) WriteLog

func (l *LoggerConsole) WriteLog(log LogData)

type Method

type Method int
const (
	GET Method = iota + 1
	POST
	PUT
	DELETE
	PATCH
	HEAD
	OPTIONS
)

func (Method) String

func (m Method) String() string

type PackageType

type PackageType int
const (
	PackageRequest PackageType = iota + 1
	PackageResponse
	PackageEvent
)

type PrintSpanParent

type PrintSpanParent struct {
	Name         string
	Traceid      string
	Callinglevel int
	Last         bool
}

type RegistryAction

type RegistryAction struct {
	Name   string      `json:"name" mapstructure:"name"`
	Rest   Rest        `json:"rest" mapstructure:"rest"`
	Params interface{} `json:"params" mapstructure:"params"`
}

type RegistryEvent

type RegistryEvent struct {
	Name   string      `json:"name" mapstructure:"name"`
	Params interface{} `json:"params" mapstructure:"params"`
}

type RegistryNode

type RegistryNode struct {
	NodeId     string   `json:"node_id" mapstructure:"node_id"`
	IP         []string `json:"ip" mapstructure:"ip"`
	LastActive int      `json:"last_active" mapstructure:"last_active"`
}

type RegistryService

type RegistryService struct {
	Node    RegistryNode     `json:"node" mapstructure:"node"`
	Name    string           `json:"name" mapstructure:"name"`
	Actions []RegistryAction `json:"actions" mapstructure:"actions"`
	Events  []RegistryEvent  `json:"events" mapstructure:"events"`
}

type RequestTranferData

type RequestTranferData struct {
	Params            interface{} `json:"params" mapstructure:"params"`
	Meta              interface{} `json:"meta" mapstructure:"meta"`
	RequestId         string      `json:"request_id" mapstructure:"request_id"`
	ResponseId        string      `json:"response_id" mapstructure:"response_id"`
	TraceParentId     string      `json:"trace_parent_id" mapstructure:"trace_parent_id"`
	TraceRootParentId string      `json:"trace_root_parent_id" mapstructure:"trace_root_parent_id"`
	CallerNodeId      string      `json:"caller_node_id" mapstructure:"caller_node_id"`
	CallerService     string      `json:"caller_service" mapstructure:"caller_service"`
	CallerAction      string      `json:"caller_action" mapstructure:"caller_action"`
	CallerEvent       string      `json:"caller_event" mapstructure:"caller_event"`
	CallingLevel      int         `json:"calling_level" mapstructure:"calling_level"`
	CalledTime        int64       `json:"called_time" mapstructure:"called_time"`
	CallToService     string      `json:"call_to_service" mapstructure:"call_to_service"`
	CallToAction      string      `json:"call_to_action" mapstructure:"call_to_action"`
	CallToEvent       string      `json:"call_to_event" mapstructure:"call_to_event"`
}

type ResponseTranferData

type ResponseTranferData struct {
	Data            interface{} `json:"data" mapstructure:"data"`
	Error           bool        `json:"error" mapstructure:"error"`
	ErrorMessage    string      `json:"error_message" mapstructure:"error_message"`
	ResponseId      string      `json:"response_id" mapstructure:"response_id"`
	ResponseNodeId  string      `json:"response_node_id" mapstructure:"response_node_id"`
	ResponseService string      `json:"response_service" mapstructure:"response_service"`
	ResponseAction  string      `json:"response_action" mapstructure:"response_action"`
	ResponseTime    int64       `json:"response_time" mapstructure:"response_time"`
	TraceSpans      []traceSpan `json:"trace_spans" mapstructure:"trace_spans"`
}

type Rest

type Rest struct {
	Method Method `json:"method" mapstructure:"method"`
	Path   string `json:"path" mapstructure:"path"`
}

type Service

type Service struct {
	Name    string
	Actions []Action
	Events  []Event
	Started func(*Context)
	Stoped  func(*Context)
	Broker  *Broker
}

func InitGateway

func InitGateway(config GatewayConfig) *Service

type TopicDisconnectData

type TopicDisconnectData struct {
	Sender  RegistryNode `json:"sender" mapstructure:"sender"`
	Time    uint64       `json:"time" mapstructure:"time"`
	Arrived uint64       `json:"arrived" mapstructure:"arrived"`
}

type TopicDiscoveryData

type TopicDiscoveryData struct {
	Sender RegistryNode `json:"sender" mapstructure:"sender"`
}

type TopicHeartbeatData

type TopicHeartbeatData struct {
	Sender RegistryNode `json:"sender" mapstructure:"sender"`
	Cpu    float64      `json:"cpu" mapstructure:"cpu"`
	Ram    int          `json:"ram" mapstructure:"ram"`
}

type TopicInfoData

type TopicInfoData struct {
	Sender   RegistryNode      `json:"sender" mapstructure:"sender"`
	Services []RegistryService `json:"services" mapstructure:"services"`
}

type TopicPingData

type TopicPingData struct {
	Sender RegistryNode `json:"sender" mapstructure:"sender"`
	Time   uint64       `json:"time" mapstructure:"time"`
}

type TopicPongData

type TopicPongData struct {
	Sender  RegistryNode `json:"sender" mapstructure:"sender"`
	Time    uint64       `json:"time" mapstructure:"time"`
	Arrived uint64       `json:"arrived" mapstructure:"arrived"`
}

type Trace

type Trace struct {
	Exporter interface{}
	Lock     sync.RWMutex
}

type TraceConfig

type TraceConfig struct {
	Enabled             bool
	WindowTime          int
	TraceExpoter        TraceExpoter
	TraceExporterConfig interface{}
}

type TraceConsoleConfig

type TraceConsoleConfig struct {
}

type TraceExpoter

type TraceExpoter int
const (
	TraceExporterConsole TraceExpoter = iota + 1
	TraceExporterDDDog
)

type Transporter

type Transporter struct {
	Config    TransporterConfig
	Subscribe func(channel string) interface{}
	Emit      func(channel string, data interface{}) error
	Receive   func(func(string, interface{}, error), interface{})
}

type TransporterConfig

type TransporterConfig struct {
	Enable          bool
	TransporterType TransporterType
	Config          interface{}
}

type TransporterRedisConfig

type TransporterRedisConfig struct {
	Port     int
	Host     string
	Password string
	Db       int
}

type TransporterType

type TransporterType int
const (
	TransporterTypeRedis TransporterType = iota + 1
)

Jump to

Keyboard shortcuts

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