go_consul

package
v0.0.0-...-43ad84a Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2023 License: MIT Imports: 4 Imported by: 0

README

goservice

Базовый пакет для сервисов написанных на golang

Возможности:

  • Регистрация сервиса в consul
  • Получение списка сервисов из consul
Регистрация сервиса в consul
package main

import "github.com/dsxack/goservice"

const (
	serviceName = "go-blank-http-server"
	servicePort = 80
)

func main() {
	err := goservice.InitConsulClient("http://consul:8500")
	if err != nil {
		panic(err)
	}
	
	err = goservice.RegisterConsulService(goservice.ConsulServiceRegistration{
		Name:          serviceName,
		Port:          servicePort,
		HealthCheck:   "/health",
	})
	if err != nil {
		panic(err)
	}
}
Получение списка сервисов из consul
package main

import (
	"github.com/dsxack/goservice"
)

func main() {
	err := goservice.InitConsulClient("http://consul:8500")
	if err != nil {
		panic(err)
	}
	
	services, _, err := goservice.DiscoverConsulService("go-blank-http-server")
	if err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

View Source
const (
	PublicWebServiceTag = "web"
)

Variables

This section is empty.

Functions

func DiscoverConsulService

func DiscoverConsulService(name string) ([]*consul.ServiceEntry, *consul.QueryMeta, error)

Discover consul service by name

func InitConsulClient

func InitConsulClient(address string) (err error)

Init consul client by address

func RegisterConsulService

func RegisterConsulService(config ConsulServiceRegistration) (err error)

Register new consul service by config params

Types

type ConsulServiceRegistration

type ConsulServiceRegistration struct {
	// Consul service name
	Name string

	// Consul service id
	ID string

	// Consul service port
	Port int

	// Consul service health check url address
	HealthCheck string

	// Consul service tags
	Tags []string
}

Service config

Jump to

Keyboard shortcuts

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