Exemple #1
0
func Example() {
	var (
		g           = cflag.NewGroup(nil, "Program Options")
		bindFlag    = cflag.String(g, "bind", ":80", "Address to bind server to (e.g. :80)")
		fooFlag     = cflag.String(g, "foo", "", "Some flag")
		barFlag     = cflag.Int(g, "bar", 42, "Some other flag")
		doStuffFlag = cflag.Bool(g, "doStuff", false, "Do stuff?")
	)

	adaptflag.Adapt()
	flag.Parse()

	fmt.Printf("Bind: %s\n", bindFlag.Value())
	fmt.Printf("Foo:  %s\n", fooFlag.Value())
	fmt.Printf("Bar:  %d\n", barFlag.Value())
	fmt.Printf("Do Stuff: %v\n", doStuffFlag.Value())
}
Exemple #2
0
package examplelib

import "gopkg.in/hlandau/easyconfig.v1/cflag"

var g = cflag.NewGroup(nil, "Server Options")
var bindFlag = cflag.String(g, "bind", ":53", "Address to bind to (e.g. 0.0.0.0:53)")
var publicKeyFlag = cflag.String(g, "publicKey", "", "Path to the DNSKEY KSK public key file")
var privateKeyFlag = cflag.String(g, "privateKey", "", "Path to the KSK's corresponding private key file")
var zonePublicKeyFlag = cflag.String(g, "zonePublicKey", "", "Path to the DNSKEY ZSK public key file; if one is not specified, a temporary one is generated on startup and used only for the duration of that process")
var zonePrivateKeyFlag = cflag.String(g, "zonePrivateKey", "", "Path to the ZSK's corresponding private key file")
var namecoinRPCUsernameFlag = cflag.String(g, "namecoinRPCUsername", "", "Namecoin RPC username")
var namecoinRPCPasswordFlag = cflag.String(g, "namecoinRPCPassword", "", "Namecoin RPC password")
var namecoinRPCAddressFlag = cflag.String(g, "namecoinRPCAddress", "localhost:8336", "Namecoin RPC server address")
var cacheMaxEntriesFlag = cflag.Int(g, "cacheMaxEntries", 100, "Maximum name cache entries")
var selfNameFlag = cflag.String(g, "selfName", "", "The FQDN of this nameserver; if empty, a psuedo-hostname is generated")
var selfIPFlag = cflag.String(g, "selfIP", "127.127.127.127", "The canonical IP address for this service")
var httpListenAddrFlag = cflag.String(g, "httpListenAddr", "", "Address for the webserver to listen at (default: disabled)")
var canonicalSuffixFlag = cflag.String(g, "canonicalSuffix", "bit", "Suffix to advertise via HTTP")
var canonicalNameserversFlag = cflag.String(g, "canonicalNameservers", "", "Comma-separated list of nameservers to use for NS records; if blank, selfName (or autogenerated psuedo-hostname) is used")
var hostmasterFlag = cflag.String(g, "hostmaster", "", "Hostmaster e. mail address")
var vanityIPs = cflag.String(g, "vanityIPs", "", "Comma separated list of IP addresses to place in A/AAAA records at the zone apex (default: don't add any records)")
var doStuff = cflag.Bool(g, "doStuff", false, "Do stuff")
Exemple #3
0
package dbutil

import "github.com/jackc/pgx"
import "strings"
import "gopkg.in/hlandau/easyconfig.v1/cflag"

var maxConnectionsFlag = cflag.Int(nil, "maxpgconnections", 2, "Maximum number of PostgreSQL pool connections")

func NewPgxPool(url string) (*pgx.ConnPool, error) {
	dbcfg := pgx.ConnPoolConfig{
		MaxConnections: maxConnectionsFlag.Value(),
	}

	var err error
	if url == "" {
		dbcfg.ConnConfig, err = pgx.ParseEnvLibpq()
	} else if strings.HasPrefix(url, "postgresql://") {
		dbcfg.ConnConfig, err = pgx.ParseURI(url)
	} else {
		dbcfg.ConnConfig, err = pgx.ParseDSN(url)
	}

	if err != nil {
		return nil, err
	}

	return pgx.NewConnPool(dbcfg)
}
Exemple #4
0
import "io"
import "gopkg.in/alexcesaro/quotedprintable.v3"
import "mime/multipart"
import "net/textproto"

var cEmailsSent = cexp.NewCounter("sendemail.emailsSent")

var log, Log = xlog.New("sendemail")

var (
	fg               = cflag.NewGroup(nil, "sendemail")
	smtpAddressFlag  = cflag.String(fg, "smtpaddress", "", "SMTP address (hostname[:port])")
	smtpUsernameFlag = cflag.String(fg, "smtpusername", "", "SMTP username")
	smtpPasswordFlag = cflag.String(fg, "smtppassword", "", "SMTP password")
	sendmailPathFlag = cflag.String(fg, "sendmailpath", "", "path to /usr/sbin/sendmail")
	numSendersFlag   = cflag.Int(fg, "numsenders", 2, "number of asynchronous e. mail senders")
	fromFlag         = cflag.String(fg, "from", "nobody@localhost", "Default from address")
)

var sendChan = make(chan *Email, 32)
var startOnce sync.Once

func sendLoop() {
	for e := range sendChan {
		err := Send(e)
		log.Errore(err, "cannot send e. mail")
	}
}

func startSenders() {
	startOnce.Do(func() {