예제 #1
0
파일: main.go 프로젝트: anarcher/envconf
func confFilePaths() []string {
	var paths []string

	if len(flag.Args()) >= 0 {
		for _, path := range flag.Args() {
			paths = append(paths, path)
		}
	}

	if val := os.Getenv(CONF_FILES); val != "" {
		for _, path := range strings.Split(val, ":") {
			paths = append(paths, path)
		}
	}
	return paths
}
예제 #2
0
파일: main.go 프로젝트: bentrevor/calhoun
func main() {
	var (
		rootDir   string
		assetPath string
		srvPath   string
		ui        string
	)

	flag.StringVar(&rootDir, "root-dir", "/home/vagrant/go/src/github.com/bentrevor/calhoun", "project root")
	flag.StringVar(&assetPath, "asset-path", "web/assets", "asset path")
	flag.StringVar(&srvPath, "srv-path", fmt.Sprintf("%s/images/srv", assetPath), "path to save uploaded files")
	flag.StringVar(&ui, "ui", "web", "")

	flag.Parse()

	var server app.CalhounServer
	postgresDB := db.NewPostgresDB("dev")
	realFS := db.RealFS{RootDir: srvPath}
	store := app.CalhounStore{DB: postgresDB, FS: realFS, SrvPath: srvPath}
	calhoun := app.Calhoun{Store: store}

	switch ui {
	case "web":
		calhoun.Renderer = web.BrowserRenderer{
			ViewsPath:  fmt.Sprintf("%s/web/views", rootDir),
			PhotosPath: srvPath,
		}

		server = &web.WebServer{
			App:           calhoun,
			AssetPath:     assetPath,
			FullAssetPath: fmt.Sprintf("%s/%s", rootDir, assetPath),
		}
	case "cli":
		calhoun.Renderer = cli.ConsoleRenderer{}

		server = cli.ConsoleServer{
			App:  calhoun,
			Args: flag.Args(),
		}
	default:
		log.Fatal(ui, " not supported")
	}

	app.Run("dev", server)
}
예제 #3
0
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)
		if err != nil {
			log.Fatal(err)
		}

		files[path] = string(data)
	}

	// JSON-encode the files
	input, err := json.Marshal(&files)
	if err != nil {
		log.Fatal(err)
	}

	// Send it to the API
	req, err := http.NewRequest("POST", *apiURL+"/maps/"+*commit, bytes.NewReader(input))
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("Content-Type", "application/json; charset=utf-8")
	req.Header.Set("Authorization", "Bearer "+*token)
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Fatal(err)
	}

	// Write the result
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("%d: %s", resp.StatusCode, string(body))
}