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()) }
"gopkg.in/hlandau/easyconfig.v1/cflag" "gopkg.in/hlandau/passlib.v1" "html" "io" "mime/multipart" "net/http" "net/mail" "net/textproto" "net/url" "regexp" "strings" "time" ) var authGroup = cflag.NewGroup(nil, "auth") var registerCAPTCHAFlag = cflag.Bool(authGroup, "registercaptcha", false, "Require CAPTCHA on register?") var log, Log = xlog.New("web.auth") type Backend interface { GetDatabase() *pgx.ConnPool GetCAPTCHA() *captcha.Config } type GetBackendFunc func(req *http.Request) Backend var GetBackend GetBackendFunc func Auth_Login_GET(rw http.ResponseWriter, req *http.Request) { tpl.MustShow(req, "auth/login", nil) }
"os" "strconv" ) // This will always point to a path which the platform guarantees is an empty // directory. You can use it as your default chroot path if your service doesn't // access the filesystem after it's started. // // On Linux, the FHS provides that "/var/empty" is an empty directory, so it // points to that. var EmptyChrootPath = daemon.EmptyChrootPath var ( uidFlag = cflag.String(fg, "uid", "", "UID to run as (default: don't drop privileges)") gidFlag = cflag.String(fg, "gid", "", "GID to run as (default: don't drop privileges)") daemonizeFlag = cflag.Bool(fg, "daemon", false, "Run as daemon? (doesn't fork)") chrootFlag = cflag.String(fg, "chroot", "", "Chroot to a directory (must set UID, GID) (\"/\" disables)") pidfileFlag = cflag.String(fg, "pidfile", "", "Write PID to file with given filename and hold a write lock") forkFlag = cflag.Bool(fg, "fork", false, "Fork? (implies -daemon)") ) func systemdUpdateStatus(status string) error { return sdnotify.Send(status) } func setproctitle(status string) error { gspt.SetProcTitle(status) return nil } func (info *Info) serviceMain() error {
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")
"os" "strconv" ) // This will always point to a path which the platform guarantees is an empty // directory. You can use it as your default chroot path if your service doesn't // access the filesystem after it's started. // // On Linux, the FHS provides that "/var/empty" is an empty directory, so it // points to that. var EmptyChrootPath = daemon.EmptyChrootPath var ( uidFlag = cflag.String(fg, "uid", "", "UID to run as (default: don't drop privileges)") gidFlag = cflag.String(fg, "gid", "", "GID to run as (default: don't drop privileges)") daemonizeFlag = cflag.Bool(fg, "daemon", false, "Run as daemon? (doesn't fork)") stderrFlag = cflag.Bool(fg, "stderr", false, "Keep stderr open when daemonizing") chrootFlag = cflag.String(fg, "chroot", "", "Chroot to a directory (must set UID, GID) (\"/\" disables)") pidfileFlag = cflag.String(fg, "pidfile", "", "Write PID to file with given filename and hold a write lock") forkFlag = cflag.Bool(fg, "fork", false, "Fork? (implies -daemon)") ) func systemdUpdateStatus(status string) error { return systemd.NotifySend(status) } func (info *Info) serviceMain() error { if forkFlag.Value() { isParent, err := daemon.Fork() if err != nil { return err