utils

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServiceEnvVarName  = "SERVICE_ID"
	InstanceEnvVarName = "INSTANCE_ID"
)
View Source
const (
	TCP string = "tcp"
	UDP string = "udp"
)
View Source
const (
	// LocalhostAddr contains the default interface address
	LocalhostAddr = "0.0.0.0"
)
View Source
const (
	// PathVarFormat format string to add vars to path
	PathVarFormat = "{%s}"
)

Variables

This section is empty.

Functions

func BuildRequest

func BuildRequest(method, host, path string, body interface{}) *http.Request

func DoRequest

func DoRequest(httpClient *http.Client, request *http.Request, responseBody interface{}) (int, *http.Response)

func ExtractPathVar

func ExtractPathVar(r *http.Request, varName string) (varValue string)

func NewRouter

func NewRouter(prefix string, routes []Route) (r *mux.Router)

NewRouter Creates new router with prefix and handlers for routes specified

func RandomString

func RandomString(n int) string

func SendJSONReplyOK

func SendJSONReplyOK(w http.ResponseWriter, replyContent interface{})

func StartServer

func StartServer(serviceName, hostPort string, port int, prefixPath string, routes []Route)

StartServer seeds the random generator and starts a server on the specified host and port serving the routes passed with a specified prefix.

Types

type GenericClient

type GenericClient struct {
	HostPort string
	Client   *http.Client
}

func NewGenericClient

func NewGenericClient(addr string, port int) *GenericClient

func (*GenericClient) SetHostPort

func (c *GenericClient) SetHostPort(addr string, port int)

type Node

type Node struct {
	Id   string
	Addr string
}

func NewNode

func NewNode(id, addr string) *Node

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	QueryParams []string
	HandlerFunc http.HandlerFunc
}

Route defines a Route type simpler than the one defined in gorilla mux

Jump to

Keyboard shortcuts

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