コード例 #1
0
func parseFlags() (client.Flags, error) {
	var flags client.Flags

	// Declare the flags
	flag.StringVar(&(flags.CA), "ca", "none", "For HTTPS support: none / filename of an accepted CA / unsafe (doesn't check the CA)")
	flag.StringVar(&(flags.ServerUrl), "url", "http://localhost:9000/clioud", "The server to contact")
	flag.StringVar(&(flags.SecretKey), "key", "", "A shared secret key to identify the client.")
	flag.StringVar(&(flags.TTL), "ttl", "", `TTL after which the file expires, ex: 30m. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h"`)
	flag.BoolVar(&(flags.Keepname), "keep", false, "Whether or not we must keep the filename")

	// Read them
	flag.Parse()

	// remove / on url if necessary
	if flags.ServerUrl[len(flags.ServerUrl)-1] == '/' {
		flags.ServerUrl = flags.ServerUrl[:len(flags.ServerUrl)-1]
	}

	// checks that the given ttl is correct
	if flags.TTL != "" {
		_, err := time.ParseDuration(flags.TTL)
		if err != nil {
			return flags, err
		}
	}

	return flags, nil
}
コード例 #2
0
ファイル: client.go プロジェクト: intfrr/upd
func parseFlags() (client.Flags, error) {
	var flags client.Flags

	// Declare the flags
	flag.StringVar(&(flags.CA), "ca", "none", "For HTTPS support: none / filename of an accepted CA / unsafe (doesn't check the CA)")
	flag.StringVar(&(flags.ServerUrl), "url", "http://localhost:9000/upd", "The server to contact")
	flag.StringVar(&(flags.SecretKey), "key", "", "A shared secret key to identify the client.")
	flag.StringVar(&(flags.TTL), "ttl", "", `TTL after which the file expires, ex: 30m. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h"`)
	flag.StringVar(&(flags.SearchTags), "search-tags", "", "Search by tags. If many, must be separated by a comma, an 'or' operator is used. Ex: \"may,screenshot\".")
	flag.Var(&flags.Tags, "tags", "Tags to attach to the file, separated by a comma. Ex: \"screenshot,may\"")

	// Read them
	flag.Parse()

	// remove / on url if necessary
	if flags.ServerUrl[len(flags.ServerUrl)-1] == '/' {
		flags.ServerUrl = flags.ServerUrl[:len(flags.ServerUrl)-1]
	}

	// checks that the given ttl is correct
	if flags.TTL != "" {
		_, err := time.ParseDuration(flags.TTL)
		if err != nil {
			return flags, err
		}
	}

	return flags, nil
}