Exemplo n.º 1
0
Arquivo: main.go Projeto: pote/philote
func SetupRedis() *redis.Pool {
	maxConnections := envflag.Int("REDIS_MAX_CONNECTIONS", 400, "Maximum ammount of concurrent Redis connections")
	redisURL := envflag.String("REDIS_URL", "redis://localhost:6379", "Redis database url")

	envflag.Parse()

	pool, err := redisurl.NewPoolWithURL(*redisURL, 3, *maxConnections, "240s")
	if err != nil {
		panic(err)
	}

	return pool
}
Exemplo n.º 2
0
func setupCluster(t *testing.T) *Cluster {
	var (
		hostport = envflag.String("SHEEPDOG_HOSTPORT", "", "Host:port for Sheepdog server")
	)
	envflag.Parse()

	c, err := NewCluster(*hostport)
	if err != nil {
		t.Fatalf("unable to create cluster: %s", err)
	}

	return c
}
Exemplo n.º 3
0
Arquivo: main.go Projeto: pote/philote
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	port := envflag.String("PORT", "6380", "Port in which to serve Philote websocket connections")
	envflag.Parse()

	log.Printf("[Main] Initializing Philotic Network\n")
	log.Printf("[Main] Version: %v\n", VERSION)
	log.Printf("[Main] Port: %v\n", *port)
	log.Printf("[Main] Cores: %v\n", runtime.NumCPU())

	done := make(chan bool)
	RunServer(done, *port)
}
Exemplo n.º 4
0
func main() {
	var (
		// This points to the client access token for your account on wit.ai, that you
		// will possibly have stored within an environment variable.
		accessToken = envflag.String("ACCESS_TOKEN", "", "WIT client access token")

		// The recording device you will use for voice queries.
		// Usually, you can leave it be default.
		device = flag.String("device", witai.DefaultDevice, "device name for recording input")
	)
	envflag.Parse()
	flag.Parse()

	// Create a new wit-ai context that will be used for queries.
	ctx, err := witai.NewContext(*device, *accessToken, witai.Error)
	if err != nil {
		log.Fatalln("cannot create new wit-ai context:", err)
	}

	// Always make sure to close the context once you are done.
	defer ctx.Close()

	log.Println("Say something nice now: ...")

	done := make(chan struct{})

	// Query the wit.ai voice service asyncly.
	if err := ctx.VoiceQueryAutoAsync(func(s string) {
		r, err := witai.NewResult(s)
		if err != nil || !r.IsValid() {
			return
		}
		log.Printf("Result: %q\n", r.Outcomes[0].Text)

		// We can exit now that we have the result.
		close(done)
	}); err != nil {
		log.Fatalln("cannot query wit-ai:", err)
	}

	// Wait exiting the process until the async result returns.
	<-done
}
Exemplo n.º 5
0
Arquivo: main.go Projeto: macb/notif
func main() {
	pagerkey := envflag.String("PAGERDUTY_KEY", "", "Pager API string")
	consulKV := envflag.String("CONSUL_KV_ADDR", "127.0.0.1:8500", "Address to consul to use for KV.")
	consulWatch := envflag.String("CONSUL_WATCH_ADDR", "127.0.0.1:8500", "Address to consul to use for watch.")
	bootstrap := envflag.Bool("NOTIF_BOOTSTRAP", false, "Starts the daemon in bootstrap mode. This prevents it from emitting any notifications and should be used to pre-populate the KV store with the current state of the world.")

	slackWebhook := envflag.String("SLACK_WEBHOOK_URL", "", "The webhook URL for slack.")
	slackUsername := envflag.String("SLACK_USERNAME", "notif", "The username for the slack webhook to be posted as.")
	slackChannel := envflag.String("SLACK_CHANNEL", "", "The channel for the slack webhook to be post to.")
	slackIcon := envflag.String("SLACK_ICON", "", "The icon to use when posting the slack webhook.")

	envflag.Parse()

	logrus.SetLevel(logrus.DebugLevel)
	logrus.SetFormatter(&logrus.JSONFormatter{})

	drain := make(chan *consulapi.HealthCheck)

	var pager notif.Notifier
	if *bootstrap {
		pager = &notif.NoopNotifier{}
	} else if *pagerkey != "" {
		pager = notif.NewPager(*pagerkey, nil)
	} else if *slackWebhook != "" {
		pager = notif.NewSlackNotifier(*slackUsername, *slackWebhook, *slackIcon, *slackChannel)
	} else {
		pager = &notif.PrintNotifier{}
	}

	w, err := notif.NewWatcher(*consulWatch, "checks", drain)
	if err != nil {
		logrus.WithFields(logrus.Fields{"err": err}).Error("faild to build watcher")
	}

	go w.Run()

	config := *consulapi.DefaultConfig()
	config.Address = *consulKV
	cc, err := consulapi.NewClient(&config)
	if err != nil {
		panic(err)
	}
	p := notif.NewProcessor(drain, pager, cc)
	p.Run()
}
Exemplo n.º 6
0
// LoadRepoStorage checks if the path set by REPO_STORAGE is available and
// tries to create it if it doesn't exist.
func LoadRepoStorage() error {
	wd, err := os.Getwd()
	if err != nil {
		return err
	}

	RepoStorage = *envflag.String("REPO_STORAGE", path.Join(wd, "_repo_storage"), "")

	f, err := os.Stat(RepoStorage)
	if err != nil {
		if os.IsNotExist(err) {
			return os.MkdirAll(RepoStorage, 0755)
		}
		return err
	}

	if !f.IsDir() {
		return fmt.Errorf("repo storage path %s is not a directory", RepoStorage)
	}

	return nil
}
Exemplo n.º 7
0
import (
	"database/sql"
	"os"
	"path"

	log "github.com/Sirupsen/logrus"
	"github.com/ianschenck/envflag"
	_ "github.com/mattn/go-sqlite3"
	"github.com/mikkeloscar/maze/store"
	"github.com/rubenv/sql-migrate"
	"github.com/russross/meddler"
)

var (
	driver = envflag.String("DATABASE_DRIVER", "sqlite3", "")
	config = envflag.String("DATABASE_CONFIG", "maze.sqlite", "")
)

func Load() (store.Store, error) {
	return New(*driver, *config)
}

func New(driver, config string) (store.Store, error) {
	db, err := Open(driver, config)
	if err != nil {
		return nil, err
	}

	return store.New(
		driver,
Exemplo n.º 8
0
func main() {
	var (
		hostport     = envflag.String("SHEEPDOG_HOSTPORT", "", "host:port pair for sheepdog cluster")
		readHostPort = envflag.String("SHEEPDOG_READ_HOSTPORT", "", "host:port pair for only issuing reads to sheepdog cluster")
		readDelay    = envflag.Duration("SHEEPDOG_READ_SLEEP", 0, "time to sleep between each read of test")
		payloadCount = envflag.Int("SHEEPDOG_TEST_PAYLOAD_COUNT", 10, "payload count to issue reads and writes to sheepdog")
		vdiSize      = envflag.Int("SHEEPDOG_VDI_SIZE", 1<<22, "create vdi of given size")
		vdiName      = envflag.String("SHEEPDOG_VDI_NAME", "testvdi", "name of vdi to test read/writes across")
	)
	envflag.Parse()

	c, err := picard.NewCluster(*hostport)
	if err != nil {
		log.Fatalln(err)
	}
	log.Printf("Created connection to sheepdog successfully")

	defer func() {
		if err := c.Disconnect(); err != nil {
			log.Fatalln(err)
		}
		log.Printf("Successfully disconnected!")
	}()

	vdi, err := c.CreateOpenVDI(*vdiName, uint64(*vdiSize))
	if err != nil {
		log.Fatalln(err)
	}
	log.Printf("Created and opened VDI successfully")

	defer func() {
		vdi.Close()
		if err := c.DeleteVDI(vdi.Name()); err != nil {
			log.Fatalln(err)
		}
		log.Printf("Successfully deleted vdi: %q", vdi.Name())
	}()

	rvdi := vdi
	if *readHostPort != "" {
		rc, err := picard.NewCluster(*readHostPort)
		if err != nil {
			log.Fatalln(err)
		}
		log.Printf("Created read connection to sheepdog successfully")

		defer func() {
			if err := rc.Disconnect(); err != nil {
				log.Fatalln(err)
			}
			log.Printf("Successfully disconnected for read connection!")
		}()

		rvdi, err = rc.OpenVDI(*vdiName)
		if err != nil {
			log.Fatalln(err)
		}
		log.Printf("Opened VDI successfully for reads")

		defer rvdi.Close()
	}

	vdiChan := make(chan *vdiData)

	go func() {
		if count, err := writeToVDI(vdi, vdiChan, *payloadCount); err != nil {
			log.Printf("Error while writing at %d: %s", count, err)
		}
	}()

	if count, failed, err := readFromVDI(rvdi, vdiChan, *readDelay); err != nil {
		log.Printf("Error occurred during reads:\n\tTotal: %d, Failures: %d\n\tError: %q", count, failed, err)
	}
}
Exemplo n.º 9
0
package main

import (
	"github.com/ianschenck/envflag"
	"github.com/rayram23/crdt/addonly/server"
	"github.com/rayram23/crdt/addonly/set"
	"google.golang.org/grpc"
	"log"
	"net"
	"os"
)

var (
	clusterAddr = envflag.String("CLUSTER", "", "The location of bootstrap address for clustering. If blank clustering will be disabled")
)

const (
	port = ":5051"
)

func main() {
	envflag.Parse()
	if *clusterAddr != "" {
	}
	lis, err := net.Listen("tcp", port)
	if err != nil {
		log.Fatalf("failed to listen: %v", err)
	}
	logger := log.New(os.Stdout, "server: ", log.Ldate|log.Ltime)
	s := grpc.NewServer()
	server, err := server.NewServer(*clusterAddr, logger)
Exemplo n.º 10
0
	"strings"

	"github.com/lgtmco/lgtm/remote/github"

	"github.com/gin-gonic/gin"
	"github.com/ianschenck/envflag"
)

const (
	DefaultURL   = "https://github.com"
	DefaultAPI   = "https://api.github.com/"
	DefaultScope = "user:email,read:org,public_repo"
)

var (
	server = envflag.String("GITHUB_URL", DefaultURL, "")
	client = envflag.String("GITHUB_CLIENT", "", "")
	secret = envflag.String("GITHUB_SECRET", "", "")
	scope  = envflag.String("GITHUB_SCOPE", DefaultScope, "")
)

func Remote() gin.HandlerFunc {
	remote := &github.Github{
		API:    DefaultAPI,
		URL:    *server,
		Client: *client,
		Secret: *secret,
		Scopes: strings.Split(*scope, ","),
	}
	if remote.URL != DefaultURL {
		remote.URL = strings.TrimSuffix(remote.URL, "/")
Exemplo n.º 11
0
	"net/http"
	"time"

	log "github.com/Sirupsen/logrus"
	"github.com/gin-gonic/gin"
	"github.com/ianschenck/envflag"
	"github.com/mikkeloscar/maze/checker"
	"github.com/mikkeloscar/maze/remote"
	"github.com/mikkeloscar/maze/repo"
	"github.com/mikkeloscar/maze/router"
	"github.com/mikkeloscar/maze/router/middleware/context"
	"github.com/mikkeloscar/maze/store/datastore"
)

var (
	addr = envflag.String("SERVER_ADDR", ":8080", "")

	debug    = flag.Bool("d", false, "")
	stateTTL = time.Duration(2 * time.Hour)
)

func main() {
	flag.Parse()
	envflag.Parse()

	if !*debug {
		// disbale gin debug mode
		gin.SetMode(gin.ReleaseMode)
	}

	err := repo.LoadRepoStorage()
Exemplo n.º 12
0
	"net/http"
	"time"

	"github.com/lgtmco/lgtm/router"
	"github.com/lgtmco/lgtm/router/middleware"

	"github.com/Sirupsen/logrus"
	"github.com/gin-gonic/contrib/ginrus"
	"github.com/ianschenck/envflag"
	_ "github.com/joho/godotenv/autoload"

	_ "github.com/lgtmco/lgtm/approval/org"
)

var (
	addr = envflag.String("SERVER_ADDR", ":8000", "")
	cert = envflag.String("SERVER_CERT", "", "")
	key  = envflag.String("SERVER_KEY", "", "")

	debug = envflag.Bool("DEBUG", false, "")
)

func main() {
	envflag.Parse()

	if *debug {
		logrus.SetLevel(logrus.DebugLevel)
	} else {
		logrus.SetLevel(logrus.WarnLevel)
	}
Exemplo n.º 13
0
package middleware

import (
	"github.com/lgtmco/lgtm/store/datastore"

	"github.com/gin-gonic/gin"
	"github.com/ianschenck/envflag"
)

var (
	driver     = envflag.String("DATABASE_DRIVER", "sqlite3", "")
	datasource = envflag.String("DATABASE_DATASOURCE", "lgtm.sqlite", "")
)

func Store() gin.HandlerFunc {
	store := datastore.New(*driver, *datasource)
	return func(c *gin.Context) {
		c.Set("store", store)
		c.Next()
	}
}
Exemplo n.º 14
0
	Team            string `json:"team"              toml:"team"`
	SelfApprovalOff bool   `json:"self_approval_off" toml:"self_approval_off"`
	DoMerge         bool   `json:"do_merge" toml:"do_merge"`
	DoVersion       bool   `json:"do_version" toml:"do_version"`
	ApprovalAlg     string `json:"approval_algorithm" toml:"approval_algorithm"`
	VersionAlg      string `json:"version_algorithm" toml:"version_algorithm"`
	VersionFormat   string `json:"version_format" toml:"version_format"`
	DoComment       bool   `json:"do_comment" toml:"do_comment"`
	DoDeployment    bool   `json:"do_deploy" toml:"do_deploy"`
	DeploymentMap   DeploymentConfigs
	re              *regexp.Regexp
}

var (
	approvals       = envflag.Int("LGTM_APPROVALS", 2, "")
	pattern         = envflag.String("LGTM_PATTERN", `(?i)^LGTM\s*(\S*)`, "")
	team            = envflag.String("LGTM_TEAM", "MAINTAINERS", "")
	selfApprovalOff = envflag.Bool("LGTM_SELF_APPROVAL_OFF", false, "")
	approvalAlg     = envflag.String("LGTM_APPROVAL_ALGORITHM", "simple", "")
	versionAlg      = envflag.String("LGTM_VERSION_ALGORITHM", "semver", "")
)

// ParseConfig parses a projects .lgtm file
func ParseConfig(configData []byte, deployData []byte) (*Config, error) {
	c, err := ParseConfigStr(string(configData))
	if err != nil {
		return nil, err
	}
	if c.DoDeployment {
		c.DeploymentMap, err = loadDeploymentMap(string(deployData))
	}
Exemplo n.º 15
0
	"github.com/BurntSushi/toml"
	"github.com/ianschenck/envflag"
)

type Config struct {
	Approvals       int    `json:"approvals"         toml:"approvals"`
	Pattern         string `json:"pattern"           toml:"pattern"`
	Team            string `json:"team"              toml:"team"`
	SelfApprovalOff bool   `json:"self_approval_off" toml:"self_approval_off"`

	re *regexp.Regexp
}

var (
	approvals       = envflag.Int("LGTM_APPROVALS", 2, "")
	pattern         = envflag.String("LGTM_PATTERN", "(?i)LGTM", "")
	team            = envflag.String("LGTM_TEAM", "MAINTAINERS", "")
	selfApprovalOff = envflag.Bool("LGTM_SELF_APPROVAL_OFF", false, "")
)

// ParseConfig parses a projects .lgtm file
func ParseConfig(data []byte) (*Config, error) {
	return ParseConfigStr(string(data))
}

// ParseConfigStr parses a projects .lgtm file in string format.
func ParseConfigStr(data string) (*Config, error) {
	c := new(Config)
	_, err := toml.Decode(data, c)
	if err != nil {
		return nil, err
Exemplo n.º 16
0
package remote

import (
	"net/http"

	"github.com/ianschenck/envflag"
	"github.com/mikkeloscar/maze/common/pkgconfig"
	"github.com/mikkeloscar/maze/model"
	"github.com/mikkeloscar/maze/remote/github"
)

var (
	client = envflag.String("CLIENT", "", "")
	secret = envflag.String("SECRET", "", "")
)

type Remote interface {
	// Login authenticates the session and returns the remoter user
	// details.
	Login(res http.ResponseWriter, req *http.Request) (*model.User, error)

	// Repo fetches the named repository from the remote system.
	Repo(u *model.User, owner, name string) (*model.Repo, error)

	// Perm fetches the named repository permissions from the remote system
	// for the specified user.
	Perm(u *model.User, owner, name string) (*model.Perm, error)

	// EmptyCommit creates/adds a new empty commit to a branch of a repo.
	// if srcBranch and dstBranch are different then the commit will
	// include the state of srcbranch effectively rebasing dstBranch onto