microgateway

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: MIT Imports: 17 Imported by: 0

README

micro gateway

  • api register
  • manage api
  • save api

http://{mgw.addr}/mgw api list

server name

name default "" use server address

name string

health check Optional

check method

check.method string get | post | options | put | delete

check path

check.path string /check or you path, default "" if not check

interval unit second

check.interval int check interval , default 30 second

timeout unit second

check.timeout int check timeout, default 30 second

server configure

{host}: [{api}, {api}]

demo

  • {mgw.addr} this server online address
  • {microservice.ip} you micro service address

POST http://{mgw.addr}/mgw/sign

Payload:

{
  "name": "account microserver by jack",
  "check": {
    "method": "get",
    "path": "/check",
    "interval": 30,
    "timeout": 50
  },
  "http://microservice.ip:40000": [
    "/api/users/auth",
    "/api/users/authorize",
    "/api/users/department",
    "/api/users/department/*",
    "/api/users/department/sync",
    "/api/users/dept/us/*",
    "/api/users/sync/*"
  ]
}

Documentation

Index

Constants

View Source
const ErrorCtxKey = CtxKey("handler_chain_error")

ErrorCtxKey is the context key to use when storing an error (for use with context.Context).

Variables

This section is empty.

Functions

func ErrorFunc

func ErrorFunc(w http.ResponseWriter, r *http.Request, status int)

func JoinNetworkAddress

func JoinNetworkAddress(network, host, port string) string

JoinNetworkAddress combines network, host, and port into a single address string of the form accepted by ParseNetworkAddress(). For unix sockets, the network should be "unix" (or "unixgram" or "unixpacket") and the path to the socket should be given as the host parameter.

func Listen

func Listen(addr interface{}) (net.Listener, error)

func LoadConfigFile

func LoadConfigFile(confFile string) map[string]interface{}

LoadConfigFile load yml config

func SaveConfigFile

func SaveConfigFile(conf map[string]interface{}) error

func SplitNetworkAddress

func SplitNetworkAddress(a string) (network, host, port string, err error)

SplitNetworkAddress splits a into its network, host, and port components. Note that port may be a port range (:X-Y), or omitted for unix sockets.

func WriteTextResp

func WriteTextResp(w http.ResponseWriter, status int, body string)

Types

type Core

type Core struct {
	Debug bool

	Server *http.Server
	// contains filtered or unexported fields
}

func New

func New(conf map[string]interface{}) *Core

func (*Core) ServeHTTP

func (c *Core) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Core) Start

func (c *Core) Start() error

type CtxKey

type CtxKey string

type HandlerError

type HandlerError struct {
	Err        error // the original error value and message
	StatusCode int   // the HTTP status code to associate with this error

	ID    string // generated; for identifying this error in logs
	Trace string // produced from call stack
}

HandlerError is a serializable representation of an error from within an HTTP handler.

func Error

func Error(statusCode int, err error) HandlerError

Error is a convenient way for a Handler to populate the essential fields of a HandlerError. If err is itself a HandlerError, then any essential fields that are not set will be populated.

func (HandlerError) Error

func (e HandlerError) Error() string

type NetworkAddress

type NetworkAddress struct {
	Network   string
	Host      string
	StartPort uint
	EndPort   uint
}

NetworkAddress contains the individual components for a parsed network address of the form accepted by ParseNetworkAddress(). Network should be a network value accepted by Go's net package. Port ranges are given by [StartPort, EndPort].

func ParseNetworkAddress

func ParseNetworkAddress(addr string) (NetworkAddress, error)

ParseNetworkAddress parses addr into its individual components. The input string is expected to be of the form "network/host:port-range" where any part is optional. The default network, if unspecified, is tcp. Port ranges are inclusive.

Network addresses are distinct from URLs and do not use URL syntax.

func (NetworkAddress) IsUnixNetwork

func (na NetworkAddress) IsUnixNetwork() bool

IsUnixNetwork returns true if na.Network is unix, unixgram, or unixpacket.

func (NetworkAddress) JoinHostPort

func (na NetworkAddress) JoinHostPort(offset uint) string

JoinHostPort is like net.JoinHostPort, but where the port is StartPort + offset.

func (NetworkAddress) PortRangeSize

func (na NetworkAddress) PortRangeSize() uint

PortRangeSize returns how many ports are in pa's port range. Port ranges are inclusive, so the size is the difference of start and end ports plus one.

func (NetworkAddress) String

func (na NetworkAddress) String() string

String reconstructs the address string to the form expected by ParseNetworkAddress(). If the address is a unix socket, any non-zero port will be dropped.

Directories

Path Synopsis
Package proxy is middleware that proxies HTTP requests.
Package proxy is middleware that proxies HTTP requests.

Jump to

Keyboard shortcuts

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