コード例 #1
0
ファイル: conf.go プロジェクト: kinghrothgar/gobin
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
}
コード例 #2
0
ファイル: ui_lib.go プロジェクト: jubbsy/go-ethereum
func DefaultAssetPath() string {
	var base string

	// If the current working directory is the go-ethereum dir
	// assume a debug build and use the source directory as
	// asset directory.
	pwd, _ := os.Getwd()
	if pwd == path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "ethereal") {
		base = path.Join(pwd, "assets")
	} else {
		switch runtime.GOOS {
		case "darwin":
			// Get Binary Directory
			exedir, _ := osext.ExecutableFolder()
			base = filepath.Join(exedir, "../Resources")
		case "linux":
			base = "/usr/share/ethereal"
		case "window":
			fallthrough
		default:
			base = "."
		}
	}

	return base
}
コード例 #3
0
ファイル: util.go プロジェクト: Joffcom/silver
func exeFolder() string {
	exeFolder, err := osext.ExecutableFolder()
	if err != nil {
		panic(err)
	}
	return exeFolder
}
コード例 #4
0
ファイル: me.go プロジェクト: colorsocean/utils
func GetLogsDirForMe() (string, error) {
	processImageDir, err := osext.ExecutableFolder()
	if err != nil {
		return "", err
	}
	return filepath.Join(processImageDir, "logs"), nil
}
コード例 #5
0
ファイル: main.go プロジェクト: rdterner/photoview
func (p *program) Start(s service.Service) error {
	runtime.GOMAXPROCS(runtime.NumCPU())
	p.exit = make(chan struct{})
	var err error

	p.execDir, err = osext.ExecutableFolder()
	if err != nil {
		return err
	}
	err = p.loadOrWriteConifg()
	if err != nil {
		return err
	}

	l, err := net.Listen("tcp", config.ListenOn)
	if err != nil {
		return err
	}
	p.listener = l

	if filepath.IsAbs(config.CacheFolder) {
		p.cacheDir = config.CacheFolder
	} else {
		p.cacheDir = filepath.Join(p.execDir, config.CacheFolder)
	}
	err = p.loadTemplate()
	if err != nil {
		return err
	}

	// Start should not block. Do the actual work async.
	logger.Infof("Starting. Listen to %s", config.ListenOn)
	go p.run(l)
	return nil
}
コード例 #6
0
ファイル: globallog.go プロジェクト: virtao/globallog
func getExeFilePath() (path string) {
	var err error
	if path, err = osext.ExecutableFolder(); err != nil {
		path = ""
	}
	return
}
コード例 #7
0
ファイル: config.go プロジェクト: natrim/grainbot
func (conf *Configuration) SaveToFile(file string) error {
	if conf == nil {
		return errors.New("I need valid Configuration to save!")
	}

	var filename string
	var err error

	conf.Lock()
	defer conf.Unlock()

	if file == "" {
		if conf.filepath != "" {
			filename = conf.filepath
		} else {
			var path string
			path, err = osext.ExecutableFolder() //current bin directory
			if err == nil {
				filename = filepath.Join(path, "config.json")
			} else {
				filename = "config.json"
			}
		}
	} else if !filepath.IsAbs(file) {
		var path string
		path, err = osext.ExecutableFolder() //current bin directory
		if err == nil {
			filename = filepath.Join(path, file)
		} else {
			filename = file
		}
	}

	if filename != "" {
		var cbuf []byte
		cbuf, err = json.MarshalIndent(conf, "", "    ")
		if err == nil {
			err = ioutil.WriteFile(filename, cbuf, 0644)
		}
	}

	if err != nil {
		return errors.New("Cannot save config file! " + err.Error())
	}

	return nil
}
コード例 #8
0
ファイル: main.go プロジェクト: reckhou/DoomAnalysis
func main() {
	path, _ := osext.ExecutableFolder()
	os.Chdir(path)

	go func() {
		log.Println(http.ListenAndServe(goCfgMgr.Get("basic", "Host").(string)+":10022", nil))
	}()
	DoomAnalysis.Start()
}
コード例 #9
0
ファイル: me.go プロジェクト: colorsocean/utils
func CwdToMe() error {
	exeDir, err := osext.ExecutableFolder()
	if err != nil {
		return err
	}
	err = os.Chdir(exeDir)
	if err != nil {
		return err
	}
	return nil
}
コード例 #10
0
ファイル: resources.go プロジェクト: EricBurnett/WebCmd
func ResourcePath() (string, error) {
	if len(*resource_path) > 0 {
		return *resource_path, nil
	}

	executablePath, err := osext.ExecutableFolder()
	if err != nil {
		return "", err
	}
	return filepath.Join(executablePath, "..", "src", "github.com", "EricBurnett", "WebCmd"), nil
}
コード例 #11
0
ファイル: main.go プロジェクト: andrioni/sql-runner
// Resolve the path to our SQL scripts
func resolveSqlRoot(sqlroot string, playbookPath string) (string, error) {

	switch sqlroot {
	case SQLROOT_BINARY:
		return osext.ExecutableFolder()
	case SQLROOT_PLAYBOOK:
		return filepath.Abs(filepath.Dir(playbookPath))
	default:
		return sqlroot, nil
	}
}
コード例 #12
0
ファイル: main.go プロジェクト: GeertJohan/qml-kit
// The qmlPrefix function returns an executable-related path of dir with qml files.
func qmlPrefix() (path string, err error) {
	path, err = osext.ExecutableFolder()
	if err != nil {
		return
	}
	switch runtime.GOOS {
	case "darwin":
		return filepath.Join(path, "..", "Resources", "qml"), nil
	default:
		return filepath.Join(path, "qml"), nil
	}
}
コード例 #13
0
ファイル: server.go プロジェクト: jessethegame/lush
// find the directory containing the lush resource files. looks for a
// "templates" directory in the directory of the executable. if not found try
// to look for them in GOPATH ($GOPATH/src/github.com/....). Panics if no
// resources are found.
func resourceDir() string {
	root, err := osext.ExecutableFolder()
	if err == nil {
		if _, err = os.Stat(root + "/templates"); err == nil {
			return root
		}
	}
	// didn't find <dir of executable>/templates
	p, err := build.Default.Import(basePkg, "", build.FindOnly)
	if err != nil {
		panic("Couldn't find lush resource files")
	}
	return p.Dir
}
コード例 #14
0
ファイル: init.go プロジェクト: TShadwell/NHTGD2013
func init() {
	path, err := osext.ExecutableFolder()
	database, err = new(level.Database).SetOptions(
		new(level.Options).SetCreateIfMissing(
			true,
		).SetCacheSize(
			500 * level.Megabyte,
		),
	).OpenDB(path + "/leveldb/")

	if err != nil {
		log.Fatal("Error binding database: ", err)
	}

}
コード例 #15
0
ファイル: main.go プロジェクト: palpha/redis-landlord-srv
func readConfig() *Cfg {
	// note: log will not be configured to write to file yet,
	// so who knows who'll see the log output at this stage...

	file, e := ioutil.ReadFile("./config.json")
	if e != nil {
		log.Fatalf("Unable to read config.json: %s", e)
	}

	var cfg Cfg
	json.Unmarshal(file, &cfg)

	if cfg.ManagerPath == "" {
		log.Fatalf("Strange config: %v", cfg)
	}

	if cfg.ListenPort <= 0 {
		cfg.ListenPort = 8080
	}

	if cfg.LandlordPort <= 0 {
		cfg.LandlordPort = 6380
	}

	if cfg.TenantPortBase <= 0 {
		cfg.TenantPortBase = 6381
	}

	if cfg.MaxTenants <= 0 {
		cfg.MaxTenants = 10
	}

	if cfg.LogPath == "" {
		cfg.LogPath =
			func() string {
				f, e := osext.ExecutableFolder()
				if e != nil {
					log.Fatal("Unable to read executable path, add LogPath to config.json.", e)
				}

				return f + "srv.log"
			}()
	}

	return &cfg
}
コード例 #16
0
ファイル: assets.go プロジェクト: rick147/freedom-routes
func getAssetsPath(mode string) (dir string) {
	var err error

	switch mode {
	case "source":
		dir, err = getSourceDir()
	case "runtime":
		dir, err = osext.ExecutableFolder()
	default:
		dir = mode
	}

	if err != nil {
		panic(err)
	}
	return dir
}
コード例 #17
0
ファイル: imgprovider.go プロジェクト: RickyS/qml
func main() {
	dir, e := osext.ExecutableFolder()
	if nil != e {
		fatal("osext cannot find executable folder: %v\n", e)
	}
	// Changing directory ensures the program can be run from any directory.
	// Otherwise it cannot find the qml file.

	e = os.Chdir(dir)
	if nil != e {
		fatal("cannot change wd to '%s': %v\n", dir, e)
	}

	if err := run(); err != nil {
		fatal("error: %v\n", err)
	}
}
コード例 #18
0
ファイル: config_test.go プロジェクト: egli/pipeline-cli-go
func TestNewConfigDefaultFile(t *testing.T) {
	folder, err := osext.ExecutableFolder()
	println(folder)
	if err != nil {
		t.Errorf("Unexpected error %v", err)
	}
	file, err := os.Create(folder + string(os.PathSeparator) + DEFAULT_FILE)
	_, err = file.WriteString(YAML)
	if err != nil {
		t.Errorf("Unexpected error %v", err)
	}
	err = file.Close()
	if err != nil {
		t.Errorf("Unexpected error %v", err)
	}

	cnf := NewConfig()
	tCompareCnfs(cnf, EXP, t)
}
コード例 #19
0
ファイル: main.go プロジェクト: ajem70/addaptsoft
func main() {

	m := martini.Classic()

	m.Use(render.Renderer())

	martini.Env = martini.Prod // You have to set the environment to `production` for all of secure to work properly!

	m.Use(secure.Secure(secure.Options{
		AllowedHosts:         []string{"localhost:1433"},
		SSLRedirect:          true,
		SSLHost:              "localhost:1433",
		SSLProxyHeaders:      map[string]string{"X-Forwarded-Proto": "https"},
		STSSeconds:           315360000,
		STSIncludeSubdomains: true,
		FrameDeny:            true,
		ContentTypeNosniff:   true,
		BrowserXssFilter:     true,
	}))

	model := models.New()

	m.Map(sessionStore)
	m.Map(pool)

	RouteAuth(m, model)
	RouteReminders(m, model)

	m.Map(model.DB.DB())

	m.Use(martini.Static("html_project/site_v1/public_html"))

	folderPath, err := osext.ExecutableFolder()
	if err != nil {
		log.Fatal(err)
	}

	if err := http.ListenAndServeTLS(":1433", folderPath+"/cert/myrsacert.pem", folderPath+"/cert/myrsakey.pem", m); err != nil {
		log.Fatal(err)
	}
}
コード例 #20
0
ファイル: resources.go プロジェクト: jorik041/buckler
func resourcePaths() (staticPath string, dataPath string) {
	base, err := osext.ExecutableFolder()
	if err != nil {
		log.Fatal("Could not read base dir")
	}

	staticPath = filepath.Join(base, "static")
	dataPath = filepath.Join(base, "data")
	if exists(dataPath) && exists(staticPath) {
		return
	}

	p, err := build.Default.Import(basePkg, "", build.FindOnly)
	if err != nil {
		log.Fatal("Could not find package dir")
	}

	staticPath = filepath.Join(p.Dir, "static")
	dataPath = filepath.Join(p.Dir, "data")
	return
}
コード例 #21
0
ファイル: goCfgMgr.go プロジェクト: reckhou/goCfgMgr
func init() {
	cfgPath, _ := osext.ExecutableFolder()
	cfgPath += "config/" + cfgFile
	log.Println("cfgPath:", cfgPath)

	file, err := os.Open(cfgPath)
	if err != nil {
		log.Println("Config file read error:", err)
		os.Exit(1)
	}

	fileLen, _ := file.Seek(0, 2)
	data := make([]byte, fileLen)
	file.Seek(0, 0)
	file.Read(data)

	file.Close()
	cfgContent := string(data)
	if debugEnabled {
		log.Println("cfgContent:", cfgContent)
	}

	cfgJson, errJS := js.NewJson([]byte(cfgContent))
	if errJS != nil {
		log.Println("Config format error:", err)
		os.Exit(1)
	}

	cfgMap, errJS = cfgJson.Map()
	if errJS != nil {
		log.Println("Config map error:", err)
		os.Exit(1)
	}

	if debugEnabled {
		log.Println(cfgMap)
	}
}
コード例 #22
0
ファイル: upgrade.go プロジェクト: jsalva/crp-cli
func upgrade() {
	var err error

	exe, err := osext.Executable()
	if err != nil {
		panic(err.Error())
	}

	path, err := osext.ExecutableFolder()
	if err != nil {
		panic(err.Error())
	}

	file, err := ioutil.TempFile(path, ".crp-")
	if err != nil {
		panic(err.Error())
	}
	defer file.Close()
	defer os.Remove(file.Name())

	resp, err := http.Get("https://crowdprocess.com")
	if err != nil {
		panic(err.Error())
	}
	defer resp.Body.Close()

	_, err = io.Copy(file, resp.Body)
	if err != nil {
		panic(err.Error())
	}

	err = os.Rename(file.Name(), exe)
	if err != nil {
		panic(err.Error())
	}
}
コード例 #23
0
ファイル: appconfig.go プロジェクト: folago/incoming
func LoadConfig() (c *appConfigT, e error) {
	// find out which file to load
	fPath := ""
	if _, e = os.Stat("incoming_cfg.yaml"); e == nil {
		fPath = "incoming_cfg.yaml"
	} else {
		programDir, _ := osext.ExecutableFolder()
		candPath := path.Join(programDir, "incoming_cfg.yaml")
		if _, e := os.Stat(candPath); e == nil {
			fPath = candPath
		}
	}

	if fPath == "" {
		e = fmt.Errorf("didn't find config file anywhere!")
		return
	}

	var fileContent []byte
	fileContent, e = ioutil.ReadFile(fPath)
	if e != nil {
		log.Printf("Couldn't read config file %s: %s", fPath, e.Error())
		return
	}

	// parse config file
	c = new(appConfigT)
	e = yaml.Unmarshal(fileContent, c)
	if e != nil {
		log.Printf("Couldn't parse config file %s: %s", fPath, e.Error())
		return
	}

	// TODO: fiddle in other sources for config vars: env vars, command line
	return
}
コード例 #24
0
ファイル: config.go プロジェクト: natrim/grainbot
func (conf *Configuration) LoadFromFile(file string) error {
	var pathToConfig string
	var err error
	var loaded bool

	conf.Lock()
	defer conf.Unlock()

	if file != "" {
		if filepath.IsAbs(file) {
			pathToConfig = file
		} else {
			var filename string
			filename, err = filepath.Abs(file)
			if err == nil {
				if _, err := os.Stat(filename); !os.IsNotExist(err) {
					pathToConfig = filename
				}
			}
		}
	}

	if pathToConfig == "" {
		var path string
		path, err = osext.ExecutableFolder() //current bin directory
		if err == nil {
			var filename string
			if file == "" {
				filename = filepath.Join(path, "config.json")
			} else {
				filename = filepath.Join(path, file)
			}
			if _, err := os.Stat(filename); !os.IsNotExist(err) {
				pathToConfig = filename
			}
		}
	}

	if pathToConfig != "" {
		var buff []byte
		buff, err = ioutil.ReadFile(pathToConfig)

		if err == nil {
			err = json.Unmarshal(buff, conf)
			if err == nil {
				loaded = true
				conf.filepath = pathToConfig
			}
		}
	}

	if !loaded {
		if err != nil {
			return errors.New("Cannot load config file! " + err.Error())
		} else {
			return errors.New("Cannot load config file!")
		}
	}

	return nil
}
コード例 #25
0
ファイル: slacktogo.go プロジェクト: rapidexpert/slacktogo
func main() {

	// Config Defaults
	config.BindAddr = "[::]"
	config.Port = 8080
	config.SSLCrt = ""
	config.SSLKey = ""

	// The "go run" command creates the executable in the tmp dir of the system
	// the "service" wrapper runs a strange current dir

	curdir, err := os.Getwd()
	if err != nil {
		log.Fatal(err)
	}

	//dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
	prgdir, err := osext.ExecutableFolder()
	if err != nil {
		log.Fatal(err)
	}

	// trying to find the config file
	if _, err := toml.DecodeFile(path.Join(prgdir, "config.toml"), &config); err != nil {
		if _, err := toml.DecodeFile(path.Join(curdir, "config.toml"), &config); err != nil {
			fmt.Println(err)
			return
		}
	}

	// Service Setup
	var name = "SlackToGo"
	var displayName = "Slack Team Gateway"
	var desc = "This Gateway connects two channels on different teams ins slack with each other."

	s, err := service.NewService(name, displayName, desc)
	logit = s

	if err != nil {
		fmt.Printf("%s unable to start: %s", displayName, err)
		return
	}

	if len(os.Args) > 1 {
		var err error
		verb := os.Args[1]
		switch verb {
		case "install":
			err = s.Install()
			if err != nil {
				fmt.Printf("Failed to install: %s\n", err)
				return
			}
			fmt.Printf("Service %q installed.\n", displayName)
		case "remove":
			err = s.Remove()
			if err != nil {
				fmt.Printf("Failed to remove: %s\n", err)
				return
			}
			fmt.Printf("Service %q removed.\n", displayName)
		case "start":
			err = s.Start()
			if err != nil {
				fmt.Printf("Failed to start: %s\n", err)
				return
			}
			fmt.Printf("Service %q started.\n", displayName)
		case "stop":
			err = s.Stop()
			if err != nil {
				fmt.Printf("Failed to stop: %s\n", err)
				return
			}
			fmt.Printf("Service %q stopped.\n", displayName)
		case "restart":
			err = s.Stop()
			if err != nil {
				fmt.Printf("Failed to stop: %s\n", err)
				return
			}
			fmt.Printf("Service %q stopped.\n", displayName)
			err = s.Start()
			if err != nil {
				fmt.Printf("Failed to start: %s\n", err)
				return
			}
			fmt.Printf("Service %q started.\n", displayName)
		case "check":
			checkConfig()
		case "run":
			doWork()
		}
		return
	}
	err = s.Run(func() error {
		// start
		go doWork()
		return nil
	}, func() error {
		// stop
		stopWork()
		return nil
	})
	if err != nil {
		logit.Error(err.Error())
	}
}
コード例 #26
0
ファイル: config.go プロジェクト: crohr/gondl
// localDirConfig returns the path to the local config file
func localDirConfig() string {
	// dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
	dir, err := osext.ExecutableFolder()
	panicon(err)
	return dir + configName
}
コード例 #27
0
func ServeJSFileHandler(w http.ResponseWriter, r *http.Request) {
	programDir, _ := osext.ExecutableFolder()
	filePath := path.Join(programDir, "incoming_jslib.js")
	http.ServeFile(w, r, filePath)
}
コード例 #28
0
ファイル: datapost_util.go プロジェクト: dcmsy/datapost
// GetBinPath get current exe module dir
func GetBinPath() (path string) {
	path, _ = osext.ExecutableFolder()
	return
}
コード例 #29
0
ファイル: server.go プロジェクト: xyproto/web
	// Passed verbatim to every handler on every request
	User interface{}
	// All requests are passed through this wrapper if defined
	Wrappers []Wrapper
	// Factory function that generates access loggers, only used to log requests
	AccessLogger AccessLogger
}

var (
	mainServer = NewServer()

	// Configuration of the shared server
	Config = &mainServer.Config

	// Location of the executable (ignore errors)
	exeDir, _ = osext.ExecutableFolder()
)

// Stops the web server
func (s *Server) Close() error {
	if s.l != nil {
		return s.l.Close()
	}
	return errors.New("closing non-listening web.go server")
}

// Queue response wrapper that is called after all other wrappers
func (s *Server) AddWrapper(wrap Wrapper) {
	s.Wrappers = append(s.Wrappers, wrap)
}
コード例 #30
0
ファイル: upgrade.go プロジェクト: Acidburn0zzz/crp-cli
// Upgrade checks github's latest release and downloads/replaces the current binary.
// Returns true if the binary has been replaced, false otherwise.
func Upgrade() (bool, error) {
	var err error

	response, err := client.Get(LATEST_VERSION_ADDRESS)
	if err != nil {
		return false, err
	}

	url := response.Request.URL
	paths := strings.Split(url.Path, "/")
	latestVersion := paths[len(paths)-1]

	if latestVersion == VERSION {
		return false, nil
	}

	exe, err := osext.Executable()
	if err != nil {
		return false, err
	}

	path, err := osext.ExecutableFolder()
	if err != nil {
		return false, err
	}

	file, err := ioutil.TempFile(path, ".crp-")
	if err != nil {
		return false, err
	}
	defer file.Close()
	defer os.Remove(file.Name())

	goarch := runtime.GOARCH
	goos := runtime.GOOS
	if goos == "windows" {
		goos = "win"
	}
	downloadUrl := strings.Replace(url.String(), "tag", "download", 1) + "/crowdprocess-" + goos + "-" + goarch
	if goos == "win" {
		downloadUrl += ".exe"
	}

	response, err = client.Get(downloadUrl)
	if err != nil {
		return false, err
	}
	defer response.Body.Close()

	_, err = io.Copy(file, response.Body)
	if err != nil {
		return false, err
	}

	stat, err := os.Stat(exe)
	if err != nil {
		return false, err
	}

	file.Chmod(stat.Mode())

	err = os.Rename(file.Name(), exe)
	if err != nil {
		return false, err
	}

	return true, nil
}