cfg

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2023 License: MIT Imports: 1 Imported by: 2

README

cfg

Go GoDoc Sourcegraph

A flexible features configure help library

Usage

package main

import(
    "fmt"

    "github.com/alimy/cfg"
)

func main() {
    suites := map[string][]string{
		"default": {"Sms", "Alipay", "Zinc", "MySQL", "Redis", "AliOSS", "LogZinc"},
		"develop": {"Zinc", "MySQL", "AliOSS", "LogFile"},
		"slim":    {"Zinc", "MySQL", "Redis", "AliOSS", "LogFile"},
	}
	kv := map[string]string{
		"sms": "SmsJuhe",
	}

    // initialize cfg
	cfg.Initial(suites, kv)

    if cfg.If("Alipay") {
        fmt.Println("use Alipay feature")
    }

    if cfg.If("Sms") {
        sms := cfg.As("Sms")
        fmt.Println("use Sms feature and the value is %s", sms)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Use alias of Features.Use func
	Use = _features.Use

	// UseDeafult alias of Features.UseDefault func
	UseDefault = _features.UseDefault

	// As alias of Features.Cfg func
	Val = _features.Cfg

	// As alias of Features.CfgAs func
	As = _features.CfgAs

	// If alias of Features.CfgIf func
	If = _features.CfgIf

	// If alias of Features.CfgAll func
	All = _features.CfgAll

	// If alias of Features.CfgAny func
	Any = _features.CfgAny

	// In alias of Features.CfgIn func
	In = _features.CfgIn

	// On alias of Features.CfgOn func
	On = _features.CfgOn

	// Be alias of Feaures.CfgBe func
	Be = _features.CfgBe

	// Not alias of Features.CfgNot func
	Not = _features.CfgNot
)

Functions

func Initial

func Initial(suites map[string][]string, kv map[string]string)

Initial initialize features in cfg pkg

Types

type Actions

type Actions map[string]Fn

Actions feature-func map alias type

type Empty

type Empty = struct{}

Empty empty alias type

type Features

type Features struct {
	// contains filtered or unexported fields
}

Features fetures info struct

func NewFeatures

func NewFeatures(suites map[string][]string, kv map[string]string) *Features

NewFeatures create new Features instance

func (*Features) Cfg

func (f *Features) Cfg(key string) (string, bool)

Cfg get value by key if exist

func (*Features) CfgAll added in v0.4.0

func (f *Features) CfgAll(expressions ...string) bool

CfgAll check all expressions is true. Return false if any one expression in expresssions is false or expressions is empty.

func (*Features) CfgAny added in v0.4.0

func (f *Features) CfgAny(expressions ...string) bool

CfgAny check any expressions is true. Return false if all expressions is false or expressions is empty.

func (*Features) CfgAs added in v0.3.0

func (f *Features) CfgAs(key string, handle func(v string))

Cfg do the handle with param of the value by key

func (*Features) CfgBe

func (f *Features) CfgBe(expression string, handle Fn)

CfgBe check expression is true then do the handle. if expression just have a string like `Sms` is mean `Sms` whether defined in suite feature settings. expression like `Sms = SmsJuhe` is mean whether `Sms` define in suite feature settings and value is `SmsJuhe`

func (*Features) CfgIf

func (f *Features) CfgIf(expression string) bool

CfgIf check expression is true. if expression just have a string like `Sms` is mean `Sms` whether define in suite feature settings. expression like `Sms = SmsJuhe` is mean whether `Sms` define in suite feature settings and value is `SmsJuhe`

func (*Features) CfgIn

func (f *Features) CfgIn(actions Actions, defAct ...Fn)

CfgIn range actions to check item's expression is true then do the handle, defFn will handle if all items are not matched,

func (*Features) CfgNot

func (f *Features) CfgNot(expression string, handle func())

CfgNot check expression is not true then do the handle. if expression just have a string like `Sms` is mean `Sms` whether defined in suite feature settings. expression like `Sms = SmsJuhe` is mean whether `Sms` define in suite feature settings and value is `SmsJuhe`

func (*Features) CfgOn added in v0.2.0

func (f *Features) CfgOn(actions Actions, defAct ...Fn)

CfgOn range actions to check item's expression is true then do the handle and return, defFn will handle if all items are not matched,

func (*Features) Use

func (f *Features) Use(suite []string, noDefault bool)

Use use custom suite for features

func (*Features) UseDefault

func (f *Features) UseDefault()

UseDefault use default suite for features

type Fn

type Fn = func()

Fn empty argument func alias type

Jump to

Keyboard shortcuts

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