Esempio n. 1
0
func Register(b *bot.Bot) {
	if len(*chans) == 0 {
		log.Printf("skipping paste init: no channels to notify")
	}

	b.OnConnect(addServer)
	b.OnDisconnect(delServer)

	url, err := url.Parse(*psrvurl)
	if err != nil {
		log.Fatalf("paste: bad url %q: %s", *psrvurl, err)
	}

	psrv := proto.NewGoPasteWebClient(webrpc.ProtoBuf, url)
	go waitloop(psrv)
}
Esempio n. 2
0
func main() {
	flag.Parse()

	url, err := url.Parse(*baseURL)
	if err != nil {
		log.Fatalf("parse url: %s", err)
	}

	paste := proto.NewGoPasteWebClient(webrpc.JSON, url)

	in, out := proto.ToPaste{}, proto.Posted{}
	file := os.Stdin
	if *fname != "" {
		if file, err = os.Open(*fname); err != nil {
			log.Fatalf("open(%q): %s", *fname, err)
		}
		*fname = filepath.Base(*fname)
		in.Name = fname
	}
	if in.Data, err = ioutil.ReadAll(file); err != nil {
		log.Fatalf("read: %s", err)
	}

	if *name != "" {
		in.Name = name
	}

	if err := paste.Paste(&in, &out); err != nil {
		log.Fatalf("paste: %s", err)
	}

	if out.Url != nil {
		log.Printf("pasted to %s", *out.Url)
	} else {
		log.Fatalf("unknown error in paste")
	}
}