Пример #1
0
func init() {
	rand.Seed(time.Now().Unix())

	rethinkdbHost = flag.String("rethinkdb_host", "localhost", "RethinkDB hostname or IP")
	rethinkdbPort = flag.String("rethinkdb_port", "28015", "Port to connect to RethinkDB")
	env = flag.String("env", "dev", "Application environment - dev/staging/prod")
	tmpTable = flag.String("tmp_table", "tmp_"+uniuri.New(), "Table to save temporary results")
	flag.Parse()
}
Пример #2
0
func main() {

	proxyUriPtr := flag.String("proxy-url", "", "uri to listen on eg: http://proxy.com")
	originUriPtr := flag.String("origin-url", "", "origin to proxy eg: http://origin.com")
	ssoSecretPtr := flag.String("sso-secret", "", "SSO secret for origin")
	ssoUriPtr := flag.String("sso-url", "", "SSO endpoint eg: http://discourse.forum.com")

	flag.Parse()

	originUrl, err := url.Parse(*originUriPtr)

	if err != nil {
		flag.Usage()
		log.Fatal("invalid origin url")
	}

	_, err = url.Parse(*ssoUriPtr)

	if err != nil {
		flag.Usage()
		log.Fatal("invalid sso url, should point at Discourse site with enable sso")
	}

	proxyUrl, err2 := url.Parse(*proxyUriPtr)

	if err2 != nil {
		flag.Usage()
		log.Fatal("invalid proxy uri")
	}

	if *proxyUriPtr == "" || *originUriPtr == "" || *ssoSecretPtr == "" || *ssoUriPtr == "" {
		flag.Usage()
		os.Exit(1)
		return
	}

	cookieSecret := uuid.New()

	proxy := httputil.NewSingleHostReverseProxy(originUrl)

	handler := redirectIfCookieMissing(proxy, *ssoSecretPtr, cookieSecret, *ssoUriPtr)

	server := &http.Server{
		Addr:           proxyUrl.Host,
		Handler:        handler,
		ReadTimeout:    10 * time.Second,
		WriteTimeout:   10 * time.Second,
		MaxHeaderBytes: 1 << 20,
	}

	log.Fatal(server.ListenAndServe())
}
Пример #3
0
func readConfiguration() (*app.Configuration, *config, error) {
	fl := flag.CommandLine
	var appCfg app.Configuration
	var srvCfg config

	fl.StringVar(&srvCfg.HTTPAddr, "http_addr", "0.0.0.0:8080", "Address to bind HTTP server")

	fl.StringVar(&appCfg.DBDSN, "db_dsn", "sslmode=disable dbname=saypi", "postgres data source name")
	fl.IntVar(&appCfg.DBMaxIdle, "db_max_idle", 2, "maximum number of idle DB connections")
	fl.IntVar(&appCfg.DBMaxOpen, "db_max_open", 100, "maximum number of open DB connections")

	fl.IntVar(&appCfg.IPPerMinute, "per_ip_rpm", 12, "maximum number of requests per IP per minute")
	fl.IntVar(&appCfg.IPRateBurst, "per_ip_burst", 5, "maximum instantaneous burst of requests per IP")

	userSecretStr := flag.String("user_secret", "", "hex encoded secret for generating secure user tokens")

	if err := fl.Parse(os.Args[1:]); err != nil {
		return nil, nil, err
	}

	userSecret, err := hex.DecodeString(*userSecretStr)
	if err != nil {
		return nil, nil, err
	}
	appCfg.UserSecret = userSecret

	return &appCfg, &srvCfg, nil
}
Пример #4
0
func init() {
	flag.StringVar(&host, "host", "127.0.0.1", "host to bind to")
	flag.IntVar(&port, "port", 2121, "port to bind to")
	flag.StringVar(&username, "ftp-username", "ftp2s3", "FTP username")
	flag.StringVar(&password, "ftp-password", "ftp2s3", "FTP password")
	flag.StringVar(&serverName, "ftp-server-name", "FTP2S3", "FTP server name")

	flag.StringVar(&awsRegion, "aws-region", "us-east-1", "AWS region")
	flag.StringVar(&awsAccessKeyID, "aws-access-key-id", "", "AWS access key ID")
	flag.StringVar(&awsSecretAccessKey, "aws-secret-access-key", "", "AWS secret access key")
	flag.StringVar(&awsBucketName, "aws-bucket-name", "", "S3 bucket name")

	flag.String("config", "", "path to config file")

	flag.Parse()
}
Пример #5
0
import (
	"encoding/json"
	"strings"

	"github.com/Sirupsen/logrus"
	"github.com/bitly/go-nsq"
	r "github.com/dancannon/gorethink"
	"github.com/lavab/kiri"
	"github.com/lavab/worker/shared"
	"github.com/namsral/flag"
	"gopkg.in/robfig/cron.v2"
)

var (
	logFormatterType  = flag.String("log", "text", "Log formatter type")
	forceColors       = flag.Bool("force_colors", false, "Force colored prompt?")
	rethinkdbDatabase = flag.String("rethinkdb_db", "worker_dev", "Database name on the RethinkDB server")

	kiriAddresses          = flag.String("kiri_addresses", "", "Addresses of the etcd servers to use")
	kiriDiscoveryStores    = flag.String("kiri_discovery_stores", "", "Stores list for service discovery. Syntax: kind,path;kind,path")
	kiriDiscoveryRethinkDB = flag.String("kiri_discovery_rethinkdb", "rethinkdb", "Name of the RethinkDB service in SD")
	kiriDiscoveryNSQd      = flag.String("kiri_discovery_nsqd", "nsqd-tcp", "Name of the nsqd TCP server in SD")
)

var (
	log      *logrus.Logger
	producer *nsq.Producer

	mapping = map[string]cron.EntryID{}
)
Пример #6
0
	"encoding/json"
	"os"
	"runtime"
	"strings"

	"github.com/Sirupsen/logrus"
	"github.com/bitly/go-nsq"
	r "github.com/dancannon/gorethink"
	"github.com/lavab/kiri"
	"github.com/lavab/worker/shared"
	"github.com/namsral/flag"
)

var (
	// General flags
	logFormatterType = flag.String("log", "text", "Log formatter type")
	forceColors      = flag.Bool("force_colors", false, "Force colored prompt?")
	// Database-related flags
	rethinkdbDatabase = flag.String("rethinkdb_db", func() string {
		database := os.Getenv("RETHINKDB_DB")
		if database == "" {
			database = "worker_dev"
		}
		return database
	}(), "Database name on the RethinkDB server")

	kiriAddresses           = flag.String("kiri_addresses", "", "Addresses of the etcd servers to use")
	kiriDiscoveryStores     = flag.String("kiri_discovery_stores", "", "Stores list for service discovery. Syntax: kind,path;kind,path")
	kiriDiscoveryRethinkDB  = flag.String("kiri_discovery_rethinkdb", "rethinkdb", "Name of the RethinkDB service in SD")
	kiriDiscoveryNSQLookupd = flag.String("kiri_discovery_lookupd", "lookupd-http", "Name of the nsqlookupd HTTP server in SD")
)
Пример #7
0
	"strings"
	"sync"

	r "github.com/dancannon/gorethink"
	"github.com/dchest/uniuri"
	"github.com/lavab/goji"
	"github.com/lavab/goji/web"
	"github.com/lavab/raven-go"
	"github.com/namsral/flag"
	"github.com/neelance/sourcemap"

	"github.com/lavab/lavatrace/models"
)

var (
	configFlag        = flag.String("config", "", "config file to load")
	rethinkdbAddress  = flag.String("rethinkdb_address", "127.0.0.1:28015", "RethinkDB address")
	rethinkdbDatabase = flag.String("rethinkdb_database", "lavatrace", "Name of the RethinkDB database to use")
	adminToken        = flag.String("admin_token", uniuri.NewLen(uniuri.UUIDLen), "Admin token for source map uploads")
	ravenDSN          = flag.String("raven_dsn", "", "Raven DSN")
)

var (
	session *r.Session
)

type Map struct {
	ID     string `json:"id" gorethink:"id"`
	Commit string `json:"commit" gorethink:"commit"`
	Name   string `json:"name" gorethink:"name"`
	Body   string `json:"body" gorethink:"body"`
Пример #8
0
	"net/http"
	"net/smtp"
	"sort"
	"sync"
	"time"

	"github.com/alexcesaro/quotedprintable"
	r "github.com/dancannon/gorethink"
	"github.com/dchest/uniuri"
	"github.com/eaigner/dkim"
	"github.com/lavab/api/models"
	"github.com/namsral/flag"
)

var (
	rethinkAddress  = flag.String("rethinkdb_address", "172.16.0.1:28015", "Address of the RethinkDB server")
	rethinkDatabase = flag.String("rethinkdb_database", "prod", "RethinkDB database to use")

	apiURL       = flag.String("api_url", "https://api.lavaboom.com", "URL of the API to use")
	smtpdAddress = flag.String("smtpd_address", "172.16.0.1:2525", "Address of the forwarding email server")
	dkimKey      = flag.String("dkim_key", "./dkim.key", "Path of the DKIM key")
)

func main() {
	flag.Parse()

	key, err := ioutil.ReadFile(*dkimKey)
	if err != nil {
		log.Fatal(err)
	}
Пример #9
0
package main

import (
	"bytes"
	"encoding/json"
	"io/ioutil"
	"log"
	"net/http"

	"github.com/namsral/flag"
)

var (
	apiURL = flag.String("api_url", "https://trace.lavaboom.com", "URL of the Lavatrace API")
	token  = flag.String("token", "", "Admin token to use")
	commit = flag.String("commit", "", "ID of the current commit")
)

func main() {
	// Parse the flags
	flag.Parse()

	// Ensure that admin token and commit are set
	if *token == "" || *commit == "" {
		log.Fatal("Invalid arguments")
	}

	// Try to load all files
	files := map[string]string{}
	for _, path := range flag.Args() {
		data, err := ioutil.ReadFile(path)
Пример #10
0
package main

import (
	"github.com/namsral/flag"
	"github.com/syfaro/finch"
	_ "github.com/syfaro/finch/commands/help"
	_ "github.com/syfaro/finch/commands/info"
	_ "xeserv.us/commands/countdown"
	_ "xeserv.us/commands/printerfacts"
)

var (
	apiToken = flag.String("api-token", "", "telegram API token")
)

func init() {
	flag.String("config", "", "configuration file")
}

func main() {
	flag.Parse()

	f := finch.NewFinch(*apiToken)

	f.Start()
}
Пример #11
0
package main

import (
	"bytes"
	"html/template"
	"log"
	"time"

	"github.com/lavab/api/client"
	"github.com/lavab/api/routes"
	"github.com/namsral/flag"
)

var (
	configFlag = flag.String("config", "", "Config file to read")
	apiURL     = flag.String("api_url", "https://api.lavaboom.com", "Path to the Lavaboom API")
	username   = flag.String("username", "", "Username of the Lavaboom account")
	password   = flag.String("password", "", "Either password or a SHA256 hash of the account's password")
	privateKey = flag.String("private_key", "", "Path to the private key")
)

type tplInput struct {
	FirstName string
}

func main() {
	flag.Parse()

	var (
		welcomeTpl  = template.Must(template.New("welcome").Parse(welcomeTemplate))
		startedTpl  = template.Must(template.New("started").Parse(startedTemplate))
Пример #12
0
package main

import (
	"net"
	"net/http"
	"os"
	"strings"

	"github.com/Sirupsen/logrus"
	r "github.com/dancannon/gorethink"
	"github.com/lavab/goji"
	"github.com/namsral/flag"
)

var (
	configFlag        = flag.String("config", "", "config file to load")
	rethinkdbHosts    = flag.String("rethinkdb_hosts", "127.0.0.1:28015", "Addresses of the RethinkDB servers")
	rethinkdbDatabase = flag.String("rethinkdb_database", "prod", "Name of the RethinkDB database to use")
)

var (
	session *r.Session
)

func main() {
	flag.Parse()

	var err error
	session, err := r.Connect(r.ConnectOpts{
		Hosts:    strings.Split(*rethinkdbName, ","),
		Database: *rethinkdbDatabase,
Пример #13
0
package main

import (
	"runtime"
	"time"

	"github.com/Xe/betterbot-common"
	"github.com/garyburd/redigo/redis"
	"github.com/namsral/flag"
)

var (
	uplink *common.Uplink
	pool   *redis.Pool

	redisServer = flag.String("redis", "127.0.0.1:6379", "redis host to connect to")
	config      = flag.String("config", "", "configuration file")
)

func main() {
	flag.Parse()

	pool = newPool(*redisServer)

	conn, err := common.Connect()
	if err != nil {
		panic(err)
	}
	uplink = conn

	conn.QueueSubscribe("betterbot.birth", "router", subBirth)
Пример #14
0
	"github.com/go-kit/kit/log"
	"github.com/go-kit/kit/metrics"
	"github.com/go-kit/kit/metrics/expvar"
	"github.com/namsral/flag"
	"golang.org/x/net/context"
	"google.golang.org/grpc"

	sgrpc "github.com/gmuch/gmuch/server/grpc"
	shttp "github.com/gmuch/gmuch/server/http"
	kitprometheus "github.com/go-kit/kit/metrics/prometheus"
	httptransport "github.com/go-kit/kit/transport/http"
	stdprometheus "github.com/prometheus/client_golang/prometheus"
)

var (
	dbPath    = flag.String("db-path", "", "The path to the folder with a '.notmuch' in it")
	debugAddr = flag.String("debug-addr", ":8000", "Address for HTTP debug/instrumentation server")
	httpAddr  = flag.String("http-addr", ":8001", "Address for HTTP (JSON) server")
	grpcAddr  = flag.String("grpc-addr", ":8002", "Address for gRPC server")
)

func main() {
	flag.Parse()

	// package log
	var logger log.Logger
	{
		logger = log.NewLogfmtLogger(os.Stderr)
		logger = log.NewContext(logger).With("ts", log.DefaultTimestampUTC).With("caller", log.DefaultCaller)
		stdlog.SetFlags(0)                             // flags are handled by Go kit's logger
		stdlog.SetOutput(log.NewStdlibAdapter(logger)) // redirect anything using stdlib log to us
Пример #15
0
import (
	"errors"
	"io"
	"io/ioutil"
	"log"
	"net/http"
	"strconv"
	"strings"

	"github.com/golang/groupcache"
	"github.com/namsral/flag"
)

var (
	// Enable config functionality
	configFlag = flag.String("config", "", "Config file to read")
	// Log output flags
	logFormatter   = flag.String("log_formatter", "text", "Log formatter type")
	logForceColors = flag.Bool("log_force_colors", false, "Force colored prompt?")
	// Proxy server settings
	proxyBind = flag.String("proxy_bind", ":5000", "Bind address of the proxy server")
	// Groupcache settings
	cacheBind   = flag.String("cache_bind", ":5001", "Bind address of the groupcache server")
	cachePublic = flag.String("cache_public", "", "Public address of the groupcache server")
	cachePeers  = flag.String("cache_peers", "", "List of peers in the groupcache cluster")
	cacheSize   = flag.Int64("cache_size", 64<<20, "Size of the LRU cache")
)

var (
	ErrInvalidContentType = errors.New("Invalid Content-Type")
	ErrTooBig             = errors.New("File is too big")
Пример #16
0
	"crypto/sha1"
	"encoding/hex"
	"encoding/json"
	"log"
	"net/http"
	"os"
	"os/signal"
	"syscall"
	"time"

	"github.com/chrissnell/syslog"
	"github.com/namsral/flag"
)

var (
	config   = flag.String("config", "", "Config file to read")
	bind     = flag.String("bind", "0.0.0.0:1514", "Address used to bind the syslog server")
	slackURL = flag.String("slack_url", "", "URL of the Slack Incoming Webhook")
)

type handler struct {
	*syslog.BaseHandler
}

type notification struct {
	Text        string        `json:"text,omitempty"`
	Attachments []*attachment `json:"attachments"`
}

type attachment struct {
	Fallback string   `json:"fallback,omitempty"`
Пример #17
0
package common

import (
	"io"
	"log"
	"os"

	"github.com/Xe/uuid"
	"github.com/namsral/flag"
	"github.com/nats-io/nats"
)

var (
	natsServer = flag.String("nats-url", "nats://nats:4242", "where to connect to for nats")
)

// Uplink to the hive
type Uplink struct {
	*nats.EncodedConn
	*log.Logger

	Nats *nats.Conn
	ID   string
}

// Connect just connects you to nats, no fuss.
func Connect() (*Uplink, error) {
	nc, err := nats.Connect(*natsServer)
	if err != nil {
		return nil, err
	}
Пример #18
0
	"net/smtp"
	"strings"

	"github.com/alexcesaro/quotedprintable"
	r "github.com/dancannon/gorethink"
	"github.com/dchest/uniuri"
	"github.com/eaigner/dkim"
	"github.com/lavab/api/models"
	man "github.com/lavab/pgp-manifest-go"
	"github.com/namsral/flag"
	"golang.org/x/crypto/openpgp"
	"golang.org/x/crypto/openpgp/armor"
)

var (
	rethinkAddress  = flag.String("rethinkdb_address", "127.0.0.1:28015", "Address of the RethinkDB server")
	rethinkDatabase = flag.String("rethinkdb_database", "dev", "RethinkDB database to use")

	apiURL           = flag.String("api_url", "https://api.lavaboom.com", "URL of the API to use")
	forwardingServer = flag.String("forwarding_server", "127.0.0.1:25", "Address of the forwarding email server")
	dkimKey          = flag.String("dkim_key", "./dkim.key", "Path of the DKIM key")
	grooveAddress    = flag.String("groove_address", "", "Address of the Groove forwarding email")
	privateKey       = flag.String("private_key", "", "Private key to use for decryption")
)

func main() {
	flag.Parse()

	keyFile, err := ioutil.ReadFile(*privateKey)
	if err != nil {
		log.Fatal(err)
Пример #19
0
	fn := func(w http.ResponseWriter, r *http.Request) {
		gifBytes := []byte{
			0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00, 0x80, 0xFF,
			0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00,
			0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44, 0x01, 0x00, 0x3B}
		w.Header().Set("Content-Type", "image/gif")
		w.Header().Set("Content-Length", "35")
		w.Header().Set("Cache-Control", "max-age=604800")
		w.Header().Set("X-Pixel", "Enjoy my pixel")
		w.Write(gifBytes)
	}
	return http.HandlerFunc(fn)
}

var (
	httpAddr      = flag.String("http", "127.0.0.1:8080", "HTTP server listen address")
	dataPath      = flag.String("data", "", "path to file containing data")
	sem           *SEManager
	data          Data
	webBugCounter uint64 = 0
)

func main() {
	flag.Parse()

	// Load data from JSON file
	data := Data{}
	fp, err := os.Open(*dataPath)
	if err != nil {
		fmt.Printf("ERROR read-file %v\n", err)
	}
Пример #20
0
package main

import (
	"github.com/Xe/betterbot-common"
	"github.com/Xe/uuid"
	"github.com/geir54/goMatrix"
	"github.com/namsral/flag"
)

var (
	uplink *common.Uplink

	config           = flag.String("config", "", "configuration file")
	matrixUser       = flag.String("matrix-username", "", "username (email address) for matrix")
	matrixPass       = flag.String("matrix-password", "", "password (not hunter2)")
	matrixHomeserver = flag.String("matrix-homeserver", "https://matrix.org", "matrix homeserver")

	botID string
)

func init() {
	flag.Parse()
}

func main() {
	conn, err := common.Connect()
	if err != nil {
		panic(err)
	}
	uplink = conn
Пример #21
0
	"net"
	"net/http"
	"time"

	"github.com/Zenithar/goproject/cmd/server/shared"
	"github.com/Zenithar/goproject/cmd/server/system"
	"github.com/Zenithar/goproject/version"

	"github.com/Sirupsen/logrus"
	"github.com/namsral/flag"
	"github.com/zenazn/goji/graceful"
)

var (
	// Enable namsral/flag logality
	configFlag = flag.String("config", "", "config file to load")

	// General flags
	bindAddress      = flag.String("bind", ":5000", "Network address used to bind")
	logFormatterType = flag.String("log", "text", "Log formatter type. Either \"json\" or \"text\"")
	forceColors      = flag.Bool("force_colors", false, "Force colored prompt?")
	ravenDSN         = flag.String("raven_dsn", "", "Defines the sentry endpoint dsn")

	databaseDriver    = flag.String("db_driver", "mongodb", "Specify the database to use (mongodb, rethinkdb)")
	databaseHost      = flag.String("db_host", "localhost:27017", "Database hosts, split by ',' to add several hosts")
	databaseNamespace = flag.String("db_namespace", "hammurapi", "Select the database")
	databaseUser      = flag.String("db_user", "", "Database user")
	databasePassword  = flag.String("db_password", "", "Database user password")

	memcachedHosts = flag.String("memcached_hosts", "", "Memcached servers for cache (ex: 127.0.0.1:11211)")
	redisHost      = flag.String("redis_host", "", "Redis server for cache")
Пример #22
0
import (
	"net/http"
	"net/http/httputil"
	"net/http/pprof"
	"net/url"
	"path/filepath"
	"strings"

	"github.com/Sirupsen/logrus"
	"github.com/gorilla/mux"
	"github.com/namsral/flag"
)

var (
	clientDir = flag.String("client", "./client", "")
	listen    = flag.String("listen", ":3000", "")
	proxy     = flag.String("proxy", "", "{prefix},{url};...")
	profile   = flag.String("profile", "", "")
)

func main() {
	flag.Parse()

	router := mux.NewRouter()

	if *proxy != "" {
		proxies := strings.Split(*proxy, ";")

		for _, proxy := range proxies {
			parts := strings.Split(proxy, ",")
Пример #23
0
func init() {
	flag.String("config", "", "configuration file")
}
Пример #24
0
package main

import (
	"log"

	r "github.com/dancannon/gorethink"
	"github.com/lavab/goji"
	"github.com/namsral/flag"
	"github.com/rs/cors"
)

var (
	rethinkAddress = flag.String("rethinkdb_address", "127.0.0.1:28015", "Address of the RethinkDB server")
	rethinkName    = flag.String("rethinkdb_name", "invite", "Name of the invitation app's database")
	rethinkAPIName = flag.String("rethinkdb_api_name", "prod", "Name of the API's database")

	session *r.Session
)

func main() {
	log.SetFlags(log.LstdFlags | log.Lshortfile)

	flag.Parse()

	// Connect to RethinkDB
	var err error
	session, err = r.Connect(r.ConnectOpts{
		Address: *rethinkAddress,
	})
	if err != nil {
		log.Fatal(err)
Пример #25
0
package main

import (
	"crypto/tls"
	"net"
	"net/http"
	"strings"

	"github.com/Sirupsen/logrus"
	"github.com/coreos/go-etcd/etcd"
	"github.com/namsral/flag"
)

var (
	configFlag       = flag.String("config", "", "Config file to read")                  // Enable config file cuntionality
	logFormatterType = flag.String("log_formatter_type", "text", "Log formatter to use") // Logrus log formatter
	logForceColors   = flag.Bool("log_force_colors", false, "Force colored log output?") // Logrus force colors
	etcdAddress      = flag.String("etcd_address", "", "Address of the etcd server to use")
	etcdPath         = flag.String("etcd_path", "", "Prefix of the etcd directory, no slash near the end")
	sessionCacheSize = flag.Int("session_cache_size", 64, "Size of the LRU client session cache")

	rawBind = flag.String("raw_bind", "0.0.0.0:80", "Address used for the HTTP server")
	tlsBind = flag.String("tls_bind", "0.0.0.0:443", "Address used for the HTTPS server")
)

var (
	tlsConfig *tls.Config
)

func main() {
	// Parse the flags
Пример #26
0
package main

import (
	"strings"

	"github.com/Sirupsen/logrus"
	"github.com/lavab/kiri"
	"github.com/namsral/flag"
)

var (
	configFlag       = flag.String("config", "", "Config file to read")                  // Enable config file cuntionality
	logFormatterType = flag.String("log_formatter_type", "text", "Log formatter to use") // Logrus log formatter
	logForceColors   = flag.Bool("log_force_colors", false, "Force colored log output?") // Logrus force colors
	etcdAddress      = flag.String("etcd_addresses", "", "Addresses of the etcd servers to use")

	services = flag.String("services", "", "Services list. Syntax: name,address,tag=val,tag=val;name,address")
	stores   = flag.String("stores", "", "Stores list. Syntax: kind,path;kind,path")
)

func main() {
	// Parse the flags
	flag.Parse()

	// Set up a new logger
	log := logrus.New()

	// Set the formatter depending on the passed flag's value
	if *logFormatterType == "text" {
		log.Formatter = &logrus.TextFormatter{
			ForceColors: *logForceColors,
Пример #27
0
package main

import (
	"log"
	"net/http"

	r "github.com/dancannon/gorethink"
	"github.com/lavab/rex/node/service"
	"github.com/namsral/flag"
)

var (
	bindAddress       = flag.String("bind_address", ":6004", "Bind address of the rexd HTTP server")
	rethinkdbAddress  = flag.String("rethinkdb_address", "172.16.0.1:28015", "RethinkDB address to use")
	rethinkdbDatabase = flag.String("rethinkdb_database", "rex", "RethinkDB database to use")
)

func main() {
	flag.Parse()

	session, err := r.Connect(r.ConnectOpts{
		Address:  *rethinkdbAddress,
		Database: *rethinkdbDatabase,
	})
	if err != nil {
		log.Fatal(err)
	}

	r.DB(*rethinkdbDatabase).TableCreate("scripts").Exec(session)

	http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
Пример #28
0
package main

import (
	"strings"

	"github.com/Sirupsen/logrus"
	r "github.com/dancannon/gorethink"
	"github.com/namsral/flag"
)

var (
	configFlag       = flag.String("config", "", "Config file to read")
	logFormatterType = flag.String("log_formatter", "text", "Log formatter type")
	logForceColors   = flag.Bool("log_force_colors", false, "Force colored prompt?")

	apiURL = flag.String("api_url", "https://api.lavaboom.com", "Path to the Lavaboom API")

	nsqdAddress       = flag.String("nsqd_address", "127.0.0.1:4150", "Address of the NSQ server")
	lookupdAddress    = flag.String("lookupd_address", "127.0.0.1:4160", "Address of the nsqlookupd server")
	rethinkdbAddress  = flag.String("rethinkdb_address", "127.0.0.1:28015", "Address of the RethinkDB server")
	rethinkdbDatabase = flag.String("rethinkdb_database", "lavabot", "RethinkDB database to use")

	enableHub    = flag.Bool("enable_hub", true, "Enable hub module")
	enableSender = flag.Bool("enable_sender", true, "Enable sender module")

	welcomeName           = flag.String("welcome_name", "welcome", "Name of the welcome template to use")
	welcomeVersion        = flag.String("welcome_version", "1.0.0", "Version of the welcome template to use")
	gettingStartedName    = flag.String("getting_name", "getting", "Name of the getting started template to use")
	gettingStartedVersion = flag.String("getting_version", "1.0.0", "Version of the getting started template to use")
	securityName          = flag.String("security_name", "security", "Name of the security info template to use")
	securityVersion       = flag.String("security_version", "1.0.0", "Version of the security info template to use")
Пример #29
0
func envOrFlag(name, help string) string {
	flag.String(name, "", help)

	return ""
}
Пример #30
0
		actions = append(actions, k)
	}
	return "[" + strings.Join(actions, ", ") + "]"
}

func (a actionsMap) validAction(action string) bool {
	_, ok := a[action]
	return ok
}

func (a actionsMap) perform(action string) error {
	return a[action]()
}

var (
	dbUser = flag.String("db_user", "expensetracker", "database user to connect with")
	dbName = flag.String("db_name", "expensetracker", "name of the database to connect to")
	dbPw   = flag.String("db_pw", "", "user's database password")
	dbHost = flag.String("db_host", "localhost", "host the database is running on")
	dbPort = flag.Int("db_port", 5432, "port the database is listening on")

	port   = flag.Int("port", 8181, "HTTP port to listen on")
	action = flag.String("action", "start", "action to perform. Available: "+actions.available())

	adminName  = flag.String("admin_name", "", "Name of admin to add")
	adminEmail = flag.String("admin_email", "", "Email of admin to add")
	adminPw    = flag.String("admin_pw", "", "Password of admin to add")
)

func DBConn() (*sqlx.DB, error) {
	return sqlx.Open("postgres",