micro

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: Apache-2.0 Imports: 17 Imported by: 13

README

micro Go Report Card GoDoc

WIP: Micro wraps gin-gonic and contains flag and environment variable configuration for providing health and metrics endpoints:

  • Basic Auth protected /healthz for liveness probes.
  • Prometheus metrics on port 2112 at /metrics.

Review the example implementation in ./examples/server.go

Configuration

Flag Environment Variable Description
-help Display help
-debug DEBUG Debug logging mode (default false)
-ip IP Server IP address to bind to. (default "127.0.0.1")
-port PORT Server port. (default "8080")
-healthz HEALTHZ Enable or disable /healthz (default true)
-healthzUser HEALTHZ_USER /healthz basic auth username (default "healthz")
-healthzPass HEALTHZ_PASS /healthz basic auth password (default "healthz")
-logout LOGOUT log output stdout | (default "stdout")
-metric METRICS Enable or Disable metrics (default true)
-metricsIP METRICS_IP Falls back to same IP as server. (default "127.0.0.1")
-metricsPort METRICS_PORT Metrics port. (default "2112")
-readTimeout READ_TIMEOUT HTTP read timeout in seconds (default 10)
-writeTimeout WRITE_TIMEOUT HTTP write timeout (default 10)
-tokenExp TOKEN_EXP JWT Token expiration in minutes (default 10)
-tokenKey TOKEN_KEY JWT Token Key
AGENT Populates the agent key of Ack.
SERVICE_ENV Populates the srv_env key of Ack.
SERVICE_NS Populates the srv_ns key of Ack.

Documentation

Overview

Copyright 2019 txn2

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Package micro is a gin-gonic wrapper.

Index

Constants

View Source
const (
	HealthzDefaultUser     = "healthz"
	HealthzDefaultPassword = "healthz"
)

Variables

This section is empty.

Functions

func HealthzHandler

func HealthzHandler() func(c *gin.Context)

func NoRouteHandler

func NoRouteHandler() func(c *gin.Context)

Types

type Client

type Client struct {
	Cfg  ClientCfg
	Http *http.Client
}

Client

func NewHttpClient

func NewHttpClient(cfg *ClientCfg) *Client

NewHttpClient

type ClientCfg

type ClientCfg struct {
	MaxIdleConnsPerHost int // 10 connections
	DialContextTimeout  int // 10 seconds
	NetTimeout          int // 10 seconds
	ConTimeout          int // 60 seconds
}

ClientCfg

type MappedMetricFamily

type MappedMetricFamily map[string]*ioprometheusclient.MetricFamily

type PxyCfg added in v0.0.6

type PxyCfg struct {
	Scheme *string // http, https
	Host   *string // elasticsearch:9200
	Strip  *string // /db
}

type Server

type Server struct {
	Cfg    *ServerCfg
	Logger *zap.Logger
	Router *gin.Engine
	Client *Client
	Token  *token.Jwt
}

func NewServer

func NewServer(serverCfg *ServerCfg) *Server

NewServer

serverCfg, _ := micro.NewServerCfg("Example")
server := micro.NewServer(serverCfg)

server.Router.GET("/test", func(c *gin.Context) {

})

server.Run()

func (*Server) ReverseProxy added in v0.0.6

func (srv *Server) ReverseProxy(cfg PxyCfg) gin.HandlerFunc

func (*Server) Run

func (srv *Server) Run()

Run server

type ServerCfg

type ServerCfg struct {
	Name         string
	Ip           string
	Port         string
	Metrics      bool
	MetricsIp    string
	MetricsPort  string
	Healthz      bool
	HealthzUser  string
	HealthzPass  string
	LogOut       string
	Debug        bool
	ReadTimeout  int
	WriteTimeout int
	ClientCfg    *ClientCfg
	TokenCfg     *token.JwtCfg
}

func NewServerCfg added in v0.0.2

func NewServerCfg(name string) (*ServerCfg, error)

Jump to

Keyboard shortcuts

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