cmode

package
v2.0.0-...-fd440d1 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

README

CMode

Package implements tools to get/set provided options (opts) via HTTP requests.

Examples

Package can be used to change log level dynamically in the running service

HTTP Handler
    // Create logrus logger for application
    appLogger := logrus.StandartLogger()

    // Create CMode option to change log level dynamically
    cmLogger := logger.New(appLogger)
    
    // Create CMode object, pass logger for logging (mandatory) and a CMode option (cmLogger).
    // You can add more self-made options (see /pkg/cmode/logger as a reference)
    cm := cmode.New(appLogger, cmLogger)

    http.Handle("/", cm.Handler())

    err := http.ListenAndServe(":8080", nil)
    if err != nil {
        appLogger.Fatalf("Server fatal error - %s", err)
    }
List of available opts and endpoints
# Curl
curl localhost:8080/cmode

# Kubectl
kubectl -n <ns> exec <pod> -- curl localhost:8080/cmode
Get options values
# Curl
curl localhost:8080/cmode/values

# Kubectl
kubectl -n <ns> exec <pod> -- curl localhost:8080/cmode/values
Set option value
# Curl
curl -X POST localhost:8080/cmode/values?loglevel=debug

# Kubectl
kubectl -n <ns> exec <pod> -- curl -X POST localhost:8080/cmode/values?loglevel=debug

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CMode

type CMode struct {
	// contains filtered or unexported fields
}
Example
appLogger := logrus.StandardLogger()

cmLogger := logger.New(appLogger)
cm := New(appLogger, cmLogger)

http.Handle("/", cm.Handler())

err := http.ListenAndServe(":8080", nil)
if err != nil {
	appLogger.Fatalf("Server fatal error - %s", err)
}
Output:

func New

func New(cmLogger Logger, opts ...CModeOpt) CMode

func (*CMode) Handler

func (cm *CMode) Handler() http.Handler

type CModeOpt

type CModeOpt interface {
	Name() string                 // Should be unique. Used in URL - '/cmode/values?$NAME=OPT_VAL'
	Get() string                  // Will be printed in '/cmode/values'
	ParseAndSet(val string) error // Argument is in ValidValues
	Description() string          // Will be printed in '/cmode'
	ValidValues() []string        // Acceptable values. Used in CMode.usage
}

type Logger

type Logger interface {
	Errorf(format string, args ...interface{}) // Printing message when option setting is failed
	Infof(format string, args ...interface{})  // Printing message when option is successfully set
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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