Ejemplo n.º 1
0
func Parse() error {
	// Change working dir to that of the executable
	exeFolder, _ := osext.ExecutableFolder()
	os.Chdir(exeFolder)

	f := flagconfig.New("gobin")
	f.StrParam("loglevel", "logging level (DEBUG, INFO, WARN, ERROR, FATAL)", "DEBUG")
	f.StrParam("logfile", "path to log file", "")
	f.StrParam("htmltemplates", "path to html templates file", filepath.Join("templates", "htmlTemplates.tmpl"))
	f.StrParam("texttemplates", "path to text templates file", filepath.Join("templates", "textTemplates.tmpl"))
	f.StrParam("staticpath", "path to static files folder", "static")
	f.IntParam("uidlength", "length of gob uid string", 4)
	f.IntParam("tokenlength", "length of the secure token string", 15)
	f.RequiredStrParam("storetype", "the data store to use")
	f.RequiredStrParam("storeconf", "a string of the form 'IP:PORT' to configure the data store")
	f.RequiredStrParam("domain", "the domain to use to for links")
	f.RequiredStrParam("pygmentizepath", "path to the pygmentize binary")
	f.RequiredStrParam("listen", "a string of the form 'IP:PORT' which program will listen on")
	f.FlagParam("V", "show version/build information", false)

	if err := f.Parse(); err != nil {
		return err
	}
	fcLock.Lock()
	defer fcLock.Unlock()
	fc = f
	//UIDLen = 4
	//StoreType = "REDIS"
	//Domain = "gobin.io"
	//Port = "6667"
	return nil
}
Ejemplo n.º 2
0
func main() {
	fc := flagconfig.New("tcp-proxy")
	fc.DisallowConfig()
	fc.StrParam("local", "Address to listen on", ":4444")
	fc.RequiredStrParam("remote", "Address to proxy to")

	if err := fc.Parse(); err != nil {
		log.Fatal(err)
	}

	Local, Remote = fc.GetStr("local"), fc.GetStr("remote")

	l, err := net.Listen("tcp", Local)
	if err != nil {
		log.Fatal(err)
	}

	for {
		lconn, err := l.Accept()
		if err != nil {
			log.Fatal(err)
		}

		rconn, err := net.Dial("tcp", Remote)
		if err != nil {
			log.Print(err)
			lconn.Close()
			continue
		}

		go CopyClose(lconn, rconn)
		go CopyClose(rconn, lconn)
	}
}