Example #1
0
func main() {
	flag.Parse()
	log.Println("start uploader")

	if flag.NArg() == 0 {
		log.Fatal("Expected file argument missing")
	}

	c, err := client.New(*serverAddr)

	if err != nil {
		log.Fatal(err)
	}

	res, _ := c.MultiUploader(flag.Args())
	var enc client.ResourceEncoder

	switch *outputType {
	case "json":
		enc = client.NewJSONEncoder(os.Stdout)
	default:
		os.Exit(0)
	}

	err = enc.Encode(res)

	if err != nil {
		log.Fatal(err)
	}
}
Example #2
0
func newCtx(srvAddr string, paths []string) (*context, error) {
	c, err := client.New(srvAddr)
	if err != nil {
		return nil, err
	}
	ctx := &context{
		files:  make(map[string]string),
		client: c,
	}

	if len(paths) > 0 {
		for _, path := range paths {
			if _, ok := ctx.files[path]; ok {
				continue
			}

			buf, err := ioutil.ReadFile(path)

			if err != nil {
				return nil, err
			}

			ctx.files[path] = string(buf)
		}
	} else {
		buf, err := ioutil.ReadAll(os.Stdin)

		if err != nil {
			return nil, err
		}

		ctx.files["stdin"] = string(buf)
	}

	return ctx, nil
}