pflagenv

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2019 License: MIT Imports: 12 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

pflagenv GoDoc

Install

go get github.com/koesie10/pflagenv

Examples

Simple example
var config = struct {
    Addr string `env:"ADDR" flag:"addr" desc:"the address for the server to listen on"`

    ChatAddr string `env:"CHAT_ADDR" flag:"chat-adr" desc:"the address of the chatsvc"`

    DiscordBotToken       string            `env:"DISCORD_BOT_TOKEN" flag:"discord-bot-token" desc:"the Discord bot token"`
    DiscordChatChannelIDs map[string]string `env:"DISCORD_CHAT_CHANNEL_IDS" flag:"discord-chat-channel-ids" desc:"the chat channel IDs in channelname=discordid format, case-sensitive"`
    DiscordChatName       string            `env:"DISCORD_CHAT_NAME" flag:"discord-chat-name" desc:"the chat name"`

    OAuthIssuer       string   `env:"OAUTH_ISSUER" flag:"oauth-issuer" desc:"OAuth issuer to retrieve configuration from"`
    OAuthClientID     string   `env:"OAUTH_CLIENT_ID" flag:"oauth-client-id" desc:"OAuth client ID"`
    OAuthClientSecret string   `env:"OAUTH_CLIENT_SECRET" flag:"oauth-client-secret" desc:"OAuth client secret"`
    OAuthScopes       []string `env:"OAUTH_SCOPES" flag:"oauth-scopes" desc:"OAuth scopes to request for the client-credentials flow"`
}{
    Addr: ":2561",

    ChatAddr: "127.0.0.1:2428",

    DiscordChatName: "Operations",

    OAuthIssuer: "http://localhost:4444",
}

flagSet := pflag.NewFlagSet("example", pflag.ExitOnError)

if err := pflagenv.Setup(flagSet, config); err != nil {
    log.Fatal(err)
}

if err := pflagenv.Parse(config); err != nil {
    log.Fatal(err)
}

fmt.Println(config.Addr)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlagValueHook

func FlagValueHook() mapstructure.DecodeHookFunc

func Int64MapHook

func Int64MapHook() mapstructure.DecodeHookFunc

func Parse

func Parse(c interface{}) error

func Setup

func Setup(fset *pflag.FlagSet, c interface{}) error

func StringMapHook

func StringMapHook() mapstructure.DecodeHookFunc

Types

This section is empty.

Jump to

Keyboard shortcuts

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