Пример #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())
}
Пример #2
0
	"gopkg.in/alexcesaro/quotedprintable.v3"
	"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)
Пример #3
0
	"gopkg.in/hlandau/svcutils.v1/exepath"
	"io"
	"net/http"
	_ "net/http/pprof" // register pprof handler for debug server
	"os"
	"os/signal"
	"runtime/pprof"
	"sync"
	"syscall"
	"time"
)

// Flags

var (
	fg                  = cflag.NewGroup(nil, "service")
	cpuProfileFlag      = cflag.String(fg, "cpuprofile", "", "Write CPU profile to file")
	debugServerAddrFlag = cflag.String(fg, "debugserveraddr", "", "Address for debug server to listen on (do not specify a public address) (default: disabled)")
)

type nullWriter struct{}

func (nw nullWriter) Write(p []byte) (n int, err error) {
	return len(p), nil
}

func init() {
	expvar.NewString("service.startTime").Set(time.Now().String())
}

// This function should typically be called directly from func main(). It takes
Пример #4
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")
Пример #5
0
import "gopkg.in/hlandau/easymetric.v1/cexp"
import "gopkg.in/hlandau/easyconfig.v1/cflag"
import "path/filepath"
import "github.com/hlandau/xlog"
import "sync"
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")