Golang bitbucket-org-kardianos-osext.ExecutableFolder类(方法)实例源码

下面列出了Golang bitbucket-org-kardianos-osext.ExecutableFolder 类(方法)源码代码实例,从而了解它的用法。

作者:kinghrothga    项目:gobi   
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
}

作者:jubbs    项目:go-ethereu   
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
}

作者:Joffco    项目:silve   
func exeFolder() string {
	exeFolder, err := osext.ExecutableFolder()
	if err != nil {
		panic(err)
	}
	return exeFolder
}

作者:colorsocea    项目:util   
func GetLogsDirForMe() (string, error) {
	processImageDir, err := osext.ExecutableFolder()
	if err != nil {
		return "", err
	}
	return filepath.Join(processImageDir, "logs"), nil
}

作者:rdterne    项目:photovie   
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
}

作者:virta    项目:globallo   
func getExeFilePath() (path string) {
	var err error
	if path, err = osext.ExecutableFolder(); err != nil {
		path = ""
	}
	return
}

作者:natri    项目:grainbo   
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
}

作者:reckho    项目:DoomAnalysi   
func main() {
	path, _ := osext.ExecutableFolder()
	os.Chdir(path)

	go func() {
		log.Println(http.ListenAndServe(goCfgMgr.Get("basic", "Host").(string)+":10022", nil))
	}()
	DoomAnalysis.Start()
}

作者:colorsocea    项目:util   
func CwdToMe() error {
	exeDir, err := osext.ExecutableFolder()
	if err != nil {
		return err
	}
	err = os.Chdir(exeDir)
	if err != nil {
		return err
	}
	return nil
}

作者:EricBurnet    项目:WebCm   
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
}

作者:andrion    项目:sql-runne   
// 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
	}
}

作者:GeertJoha    项目:qml-ki   
// 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
	}
}

作者:jessethegam    项目:lus   
// 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
}

作者:TShadwel    项目:NHTGD201   
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)
	}

}

作者:palph    项目:redis-landlord-sr   
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
}

作者:rick14    项目:freedom-route   
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
}

作者:Ricky    项目:qm   
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)
	}
}

作者:egl    项目:pipeline-cli-g   
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)
}

作者:ajem7    项目:addaptsof   
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)
	}
}

作者:jorik04    项目:buckle   
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
}


问题


面经


文章

微信
公众号

扫码关注公众号