microservicecore

package module
v3.5.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2018 License: Apache-2.0 Imports: 2 Imported by: 0

README

Lush Digital - Micro Service Core (Golang) License Go Report Card Build Status

A set of core functionality and convenience structs for a Golang microservice

Description

This package is intended to provide a quick and easy bootstrap of functionality that a micro service is expected to provide. This includes an information route that could be used by a service registry, it also includes a health check route to verify your microservice is working.

The package also contains some convenience classes to help develop microservices.

Package Contents

  • Route struct for use with HTTP routing
  • Response struct to provide a standardised response format for endpoints
  • JSON response formatter
  • Info struct to provide meta data for your service
  • Helper function to retrieve and ensure environment variables.

Installation

Install the package as normal:

$ go get -u github.com/LUSHDigital/microservice-core-golang

Documentation

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MicroserviceInfo

type MicroserviceInfo struct {
	ServiceName    string  `json:"service_name"`
	ServiceType    string  `json:"service_type"`
	ServiceScope   string  `json:"service_scope"`
	ServiceVersion string  `json:"service_version"`
	Endpoints      []Route `json:"endpoints"`
}

MicroserviceInfo - Represents information about this microservice.

func GetMicroserviceInfo

func GetMicroserviceInfo() *MicroserviceInfo

GetMicroserviceInfo - Get the information about this microservice.

Return:

*MicroserviceInfo - Object representing this microservice.
Example

ExampleGetMicroserviceInfo - Example for GetMicroserviceInfo.

envVars := map[string]string{
	"SERVICE_NAME":    "example-service",
	"SERVICE_TYPE":    "examples",
	"SERVICE_SCOPE":   "testing",
	"SERVICE_VERSION": "0.0.1",
}

// Set our expected environment variables.
for key, value := range envVars {
	os.Setenv(key, value)
}

// Get the service info.
info := GetMicroserviceInfo()

// Print the details.
fmt.Println(info.ServiceName)
fmt.Println(info.ServiceType)
fmt.Println(info.ServiceScope)
fmt.Println(info.ServiceVersion)
Output:

example-service
examples
testing
0.0.1

type Route

type Route struct {
	Path    string                                   `json:"uri"`
	Method  string                                   `json:"method"`
	Handler func(http.ResponseWriter, *http.Request) `json:"-"`
}

Route defines an HTTP route

Directories

Path Synopsis
Package pagination defines a paginator able to return formatted responses enabling the API consumer to retrieve data in defined chunks
Package pagination defines a paginator able to return formatted responses enabling the API consumer to retrieve data in defined chunks
Package response defines the how the default microservice response must look and behave like.
Package response defines the how the default microservice response must look and behave like.

Jump to

Keyboard shortcuts

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