utils

package
v0.0.0-...-ea4b12c Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeltaUint64

func DeltaUint64(inpHID, nodeHID uint64) (uint64, error)

DeltaUint64 is a fuction return |i-j| on a ring mod 2^64 due to the type of i and j is unsined int64, so it's important to test whether one parameter is greater than the other one. 2.1 inpHID = 1, nodeHID = 5 => delta = 5 - 1 = 4 2.2 inpHID = 1, nodeHID = 2^64 - 2 => delta = 2^64 - 2 - 1 = 2^64 - 3 = 18446744073709551613 2.3. inpHID = 2^64 - 2, nodeHID = 1 => delta = (2^64-1) - ((2^64-2) - 1) + 1 = 3 NOTICE: why "+1" ? because UINT64MAX = 2^64 - 1, instead of 2^64 2.4 inpHID = 5, nodeHID = 1 => delta = (2^64-1) - (5 - 1) + 1 = 2^64 - 4 = 18446744073709551612

func GetHashID

func GetHashID(input string) (HID uint64)

GetHashID is a tool function and this function return HID (int)

func GetStaticFileName

func GetStaticFileName(path string) (name string)

GetStaticFileName is a tool function if path == "static\v1\api-v1-test\1.js", return 1.js; if path == "static\v1\api-v1-test", return ""

func LoggerGenerator

func LoggerGenerator(formatter log.Formatter, output io.Writer, level log.Level) *log.Entry

LoggerGenerator is a tool function to generate *log.Entry

func ReadConfig

func ReadConfig(path string) (service []config.Service, err error)

ReadConfig is a tool func to read config file

func StaticSuffixDetermine

func StaticSuffixDetermine(name, rule string) (isStatic bool, err error)

StaticSuffixDetermine is a determiner

func StripURLPathPrefix

func StripURLPathPrefix(path, prefix string) (result string, ok bool)

StripURLPathPrefix is a tool function path: r.URL.Path (e.g. /api/v1/food/1.js, /api/v3/test/favicon.ico) prefix: service.proxy[i].src this function return result and ok(true) when working well while returning result("") and ok(false) when failing

Types

type LoggerConfig

type LoggerConfig struct {
	LogPath     string
	LogFileName string
	LogSuffix   string

	LogFormatter log.Formatter
	LogOutput    io.Writer
	LogLevel     log.Level
}

LoggerConfig is a struct to contain logrus's config

type Loggerable

type Loggerable interface {
	// Default logger should be log.NewEntry(log.New()), namely,
	// Logger{ Out: os.Stderr, Formatter: new(logrus.TextFormatter), Hooks: make(logrus.LevelHooks), Level: logrus.DebugLevel }
	// SetLogger will custom logger
	SetLogger(cfg *LoggerConfig) (err error)
}

Loggerable is an interface balabala

type MarshalUnmarshaler

type MarshalUnmarshaler interface {
	Marshaler
	Unmarshaler
}

MarshalUnmarshaler is balabala

type Marshaler

type Marshaler interface {
	Marshal(v interface{}) (res gjson.Result)
}

Marshaler is an interface turn v(interface{}) => gjson.Result

type Unmarshaler

type Unmarshaler interface {
	Unmarshal(res gjson.Result)
}

Unmarshaler is an interface

func (v interface{}) Unmarshal(res gjson.Result) turn gjson.Result => v(interface{})

Jump to

Keyboard shortcuts

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