pflagenv

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2021 License: MIT Imports: 12 Imported by: 2

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