polaris

package module
v0.0.0-...-64c0c26 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: MIT Imports: 12 Imported by: 0

README

GoFrame Polaris Plugin

Go Reference GoFrame Polaris CI Go Report Production Ready License

English | 简体中文

Use Polaris mesh as service registration management and heartbeat reporting

Installation

go get -u -v github.com/gogf/polaris

suggested using go.mod:

require github.com/gogf/polaris latest

Limitation

golang version >= 1.16

Use yaml configuration file by default

Assuming config.yaml configuration

server:
  Address: :8199
  ServerRoot: ./
  ServerAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36
  LogPath: ./logs/server
  OpenApiPath: /api.json
  SwaggerPath: /swagger
logger:
  Path: ./logs
  Level: all
  Stdout: true
database:
  link: mysql:root:root@tcp(127.0.0.1:3306)/test
  debug: true
  logger:
    Path: ./logs/sql
    Level: all
    Stdout: true

exam:
  env: app_prod

app:
  env: local
  environment: develop
  version: 1.0.0
  jaegerEndpoint: http://tracing-analysis-dc-bj.aliyuncs.com

polaris:
    # system configuration
    config:
      # Whether the heartbeat is reported
      isHeartbeat: 1
      loggerPath: ./logs/polaris
      backupPath: ./logs/polaris
    server:
      namespace: default
      service: houseme
      version: 1.0.0
      port: 8199
      ttl: 2

global:
  consumer:
    localCache:
      persistDir: $HOME/logs/backup
  serverConnector:
    connectTimeout: 1000ms
    addresses:
    - 192.168.100.222:8091
#     - 192.168.100.222:8090

Example

config.toml

main.go

Reference example

import (
	"context"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gcfg"

	"github.com/gogf/polaris"
)

func main() {
	ctx := context.Background()
	adapter, err := gcfg.NewAdapterFile("config.yaml")
	if err != nil {
		g.Log().Fatal(ctx, "boot init g cfg.NewAdapterFile error:", err)
	}
	g.Cfg().SetAdapter(adapter)

	s := g.Server()
	s.BindHandler("/", func(r *ghttp.Request) {
		r.Response.Write("hello, polaris!")
	})
	s.Plugin(polaris.GfPolarisPlugin{
		Listener: func(config string) {
			g.Log().Print(ctx, "Polaris register success")
		},
	})
	s.Run()
}

License

GoFrame Polaris is licensed under the MIT License, 100% free and open-source, forever.

Documentation

Index

Constants

View Source
const (
	// Version polaris plugin version
	Version = "0.0.1"
	// DefaultNamespace name space
	DefaultNamespace = "default"
	// DefaultService Default service name
	DefaultService = "GoGF-polaris"
	// DefaultPort default service port
	DefaultPort = 8199
	// TTL .The timeout period, if the node wants to call heartbeat to report,
	// it must be filled in, otherwise it will be 400141 error code, unit: second
	TTL int = 2
)

Variables

View Source
var (
	CfgGlobal config.Configuration
)

Functions

func Consumer

func Consumer(ctx context.Context)

Consumer .Get service list information

func Deregister

func Deregister()

Deregister anti registration service

func InitConfigPolaris

func InitConfigPolaris() error

InitConfigPolaris Polaris plug-in initialization.

Types

type ConfigListener

type ConfigListener func(config string)

ConfigListener .

type ConfigPolaris

type ConfigPolaris struct {
	// IsHeartbeat whether to enable heartbeat reporting
	IsHeartbeat uint `json:"isHeartbeat"`
	// LoggerPath log directory
	LoggerPath string `json:"loggerPath"`
	// BackupPath backup directory
	BackupPath string `json:"backupPath"`
}

ConfigPolaris config

type GfPolarisPlugin

type GfPolarisPlugin struct {
	Listener ConfigListener
}

GfPolarisPlugin .

func (GfPolarisPlugin) Author

func (p GfPolarisPlugin) Author() string

Author website of author

func (GfPolarisPlugin) Description

func (p GfPolarisPlugin) Description() string

Description desc of plugin

func (GfPolarisPlugin) Install

func (p GfPolarisPlugin) Install(s *ghttp.Server) error

Install plugin installation

func (GfPolarisPlugin) Name

func (p GfPolarisPlugin) Name() string

Name Plugin name

func (GfPolarisPlugin) Remove

func (p GfPolarisPlugin) Remove() error

Remove plugin removal

func (GfPolarisPlugin) Version

func (p GfPolarisPlugin) Version() string

Version gf Polaris plugin version

type InstanceRequest

type InstanceRequest struct {
	// Service Required, service name
	Service string
	// ServiceToken Required, service access token
	ServiceToken string
	// Namespace Required, namespace
	Namespace string
	// Host Required, service monitoring host, support IPv 6 address
	Host string
	// Port Required, service instance monitor port
	Port int

	// The following fields are optional, the default nil means that the client is not configured, and the server configuration is used
	// Protocol Service Agreement
	Protocol string
	// Weight Service weight, default 100, range 0-10000
	Weight int
	// Priority Instance priority, the default is 0, the smaller the value, the higher the priority
	Priority int
	// Version Instance provides service version number
	Version string
	// Metadata user defined metadata information
	Metadata map[string]string
	// Healthy Whether the service instance is healthy, the default is healthy
	Healthy bool
	// Isolate Whether the service instance is isolated, not isolated by default
	Isolate bool
	// TTL timeout, if the node wants to call heartbeat to report,
	// it must be filled in, otherwise it will be 400141 error code, unit: second
	TTL int

	// Timeout Optional, single query timeout time, the default is to directly obtain the global timeout configuration
	// The user's total maximum timeout time is (1+RetryCount) Timeout
	Timeout time.Duration
	// RetryCount Optional, the number of retries, the global timeout configuration is directly obtained by default
	RetryCount int
}

InstanceRequest .

func GetInstanceConfig

func GetInstanceConfig(ctx context.Context) (*InstanceRequest, error)

GetInstanceConfig .instance Config

type Polaris

type Polaris struct {
	// Config polaris configuration
	Config *ConfigPolaris `json:"config"`
	// Instance Service configuration information
	Instance *InstanceRequest `json:"server"`
}

Polaris .

Directories

Path Synopsis
example
plugin

Jump to

Keyboard shortcuts

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