Beispiel #1
0
func main() {
	flag.Parse()

	fmt.Printf("Using storage dir %s\n", *storeDir)
	r := items.New(store.NewFileSystem(*storeDir))

	args := flag.Args()

	if len(args) == 0 {
		return
	}

	switch args[0] {
	case "blob":
		doblob(r, args[1], args[2])
	case "item":
		doitem(r, args[1:])
	case "list":
		dolist(r)
	case "add":
		doadd(r, args[1], args[2:], false)
	case "set":
		doadd(r, args[1], args[2:], true)
	case "delete":
		dodelete(r, args[1], args[2:])
	}
}
Beispiel #2
0
func main() {

	// Start with the Default values
	config := bendoConfig{
		StoreDir:   ".",
		Tokenfile:  "",
		CacheDir:   "",
		CacheSize:  100,
		PortNumber: "14000",
		PProfPort:  "14001",
		Mysql:      "",
		CowHost:    "",
		CowToken:   "",
	}

	var configFile = flag.String("config-file", "", "Configuration File")

	flag.Parse()

	// If config file arg provided, try to open & decode it
	if *configFile != "" {
		log.Printf("Using config file %s\n", *configFile)
		if _, err := toml.DecodeFile(*configFile, &config); err != nil {
			log.Println(err)
			return
		}
	}

	log.Printf("Using storage dir %s\n", config.StoreDir)
	log.Printf("Using cache dir %s\n", config.CacheDir)
	var validator server.TokenValidator
	if config.Tokenfile != "" {
		var err error
		log.Printf("Using user token file %s\n", config.Tokenfile)
		validator, err = server.NewListValidatorFile(config.Tokenfile)
		if err != nil {
			log.Println(err)
			return
		}
	} else {
		log.Printf("No user token file specified")
		validator = server.NobodyValidator{}
	}
	if config.CacheDir != "" {
		os.MkdirAll(config.CacheDir, 0755)
	}
	var itemstore store.Store = store.NewFileSystem(config.StoreDir)
	if config.CowHost != "" {
		log.Printf("Using COW with target %s", config.CowHost)
		itemstore = store.NewCOW(itemstore, config.CowHost, config.CowToken)
	}
	var s = server.RESTServer{
		Items:      items.New(itemstore),
		Validator:  validator,
		MySQL:      config.Mysql,
		CacheDir:   config.CacheDir,
		CacheSize:  config.CacheSize * 1000000,
		PortNumber: config.PortNumber,
		PProfPort:  config.PProfPort,
	}
	if config.CowHost != "" {
		// don't run fixity if we are using a copy-on-write.
		// (doing so will cause us to download ALL the data from
		// the target bendo over time)
		s.DisableFixity = true
	}

	// set up signal handlers
	sig := make(chan os.Signal, 5)
	signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
	go signalHandler(sig, &s)

	s.Run()
}