• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang osext.ExecutableFolder函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/kardianos/osext.ExecutableFolder函数的典型用法代码示例。如果您正苦于以下问题:Golang ExecutableFolder函数的具体用法?Golang ExecutableFolder怎么用?Golang ExecutableFolder使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ExecutableFolder函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: init

func init() {
	var err error
	Folder, err = osext.ExecutableFolder()
	if err != nil {
		panic(err)
	}
}
开发者ID:Felamande,项目名称:filesync,代码行数:7,代码来源:settings.go


示例2: getDir

func getDir() string {
	dir, err := osext.ExecutableFolder()
	if err != nil {
		log.Fatal(err)
	}
	return dir
}
开发者ID:blurdsss,项目名称:speakeasy,代码行数:7,代码来源:speakeasy.go


示例3: GuessApp

// GuessAppFromLocation uses the location of the execution to determine the app to launch
func GuessApp() string {
	// 1) check if current directory contains .app file and load it into the ENVIRONMENT
	if _, err := ioutil.ReadFile(config.APP_FILE); err == nil {
		utils.LoadEnvironmentFile("app")
	}

	appFromFile := os.Getenv("APP")

	if len(appFromFile) > 0 {
		return appFromFile
	} else {
		// use the name of the current directory but ask for confirmation
		currentDirPath, error := osext.ExecutableFolder()
		if error != nil {
			logger.Fatal("Cannot use current directory name for the app name")
			os.Exit(1)
		} else {
			startPosition := strings.LastIndex(currentDirPath, string(os.PathSeparator)) + 1
			currentDirectoryName := currentDirPath[startPosition:]
			appNameFromDirectory := strings.ToLower(string(currentDirectoryName))

			// TODO: ask for confirmation
			fmt.Println("No app name was passed and no appfile found...")
			answer := terminal.AskForConfirmation("Do you want to use the current directory name [" + appNameFromDirectory + "] ?")
			if answer == "YES" {
				return appNameFromDirectory
			} else {
				os.Exit(0)
			}
		}

		return ""
	}
}
开发者ID:tahitianstud,项目名称:ata,代码行数:35,代码来源:functions.go


示例4: NewPsqlDao

func NewPsqlDao(conn string) *PsqlDao {
	db := PsqlDao{}
	db.conn = os.Getenv("DATABASE_URL")

	if db.conn == "" {
		log.Fatal("DATABASE_URL environment variable not set!")
	}

	db.dao = make(map[string]*sql.DB)

	// Create all the Tables, Views if they do not exist
	execPath, err := osext.ExecutableFolder()
	if err != nil {
		log.Fatal(err)
	}
	log.Println(execPath)
	db.ddl = goyesql.MustParseFile(path.Join(execPath, "data/sql/ddl.sql"))

	db.EnsurePool(AppDB)

	logExec(db.dao[AppDB], (string)(db.ddl["create-user-table"]))
	logExec(db.dao[AppDB], (string)(db.ddl["create-post-table"]))
	logExec(db.dao[AppDB], (string)(db.ddl["create-command-table"]))
	logExec(db.dao[AppDB], (string)(db.ddl["create-tag-table"]))
	logExec(db.dao[AppDB], (string)(db.ddl["create-invocation-table"]))
	logExec(db.dao[AppDB], (string)(db.ddl["create-invocationtag-table"]))
	logExec(db.dao[AppDB], (string)(db.ddl["create-commandhistory-view"]))
	logExec(db.dao[AppDB], (string)(db.ddl["create-timestamp-index"]))

	// Load all data-manipulation queries
	db.dml = goyesql.MustParseFile(path.Join(execPath, "data/sql/queries.sql"))

	log.Println("storage init completed")
	return &db
}
开发者ID:warreq,项目名称:gohstd,代码行数:35,代码来源:psql_dao.go


示例5: init

func init() {
	ThemeDir, _ = osext.ExecutableFolder()
	ThemeDir += "/../src/github.com/superhx/goblog/theme"
	templateDir = ThemeDir + "/template"
	homeTmpl, _ = template.ParseFiles(templateDir + "/home.htm")
	blogTmpl, _ = template.ParseFiles(templateDir + "/article.htm")
}
开发者ID:flytiny,项目名称:goblog,代码行数:7,代码来源:render.go


示例6: logPath

func logPath() string {
	now := time.Now().Format("2006-01-02")
	fName := fmt.Sprintf("%s.log", now)
	directory, _ := osext.ExecutableFolder()
	path := filepath.Join(directory, "logs", fName)
	return path
}
开发者ID:5Sigma,项目名称:Conduit,代码行数:7,代码来源:log.go


示例7: main

func main() {
	pwd, _ := osext.ExecutableFolder()

	config, err := ini.LoadFile(pwd + "/config.ini")
	if err != nil {
		panic("Config file not loaded.")
	}
	api_key, ok := config.Get("telegram", "token")
	if !ok {
		panic("Telegram API token not available.")
	}
	chat_id_str, ok := config.Get("telegram", "chat_id")
	if !ok {
		panic("Telegram Chat ID not available.")
	}

	os.Chdir(pwd)
	v := exec.Command("node", "version-fetcher.js")
	v.CombinedOutput()
	ver, err := ioutil.ReadFile(pwd + "/version")
	hash, err := ioutil.ReadFile(pwd + "/hash")
	c := exec.Command("gulp", "test")
	c.CombinedOutput()
	if _, err := os.Stat(pwd + "/error-msg"); os.IsNotExist(err) {
		msg := time.Now().Format("[2006-01-02 15:04]") + " Firefox Installers Check OK \nVERSION: " + string(ver) + ", SHA512: " + string(hash)[:10] + "..."
		send_msg(api_key, chat_id_str, msg)
	} else {
		msg := time.Now().Format("[2006-01-02 15:04]") + " Firefox Installers Check Failure \u2757\ufe0f\u2757\ufe0f\u2757\ufe0f \nVERSION: " + string(ver) + ", SHA512: " + string(hash)[:10] + "..."
		send_msg(api_key, chat_id_str, msg)
	}
}
开发者ID:othree,项目名称:moztw-download-validation,代码行数:31,代码来源:go.go


示例8: detectProdConfig

func detectProdConfig(useosxt bool) string {
	var levelUp string
	var curDir string
	sep := string(filepath.Separator)

	if useosxt {
		curDir, _ = os.Getwd()
	} else {
		curDir, _ = osext.ExecutableFolder()
	}

	//detect from test or console
	match, _ := regexp.MatchString("_test", curDir)
	matchArgs, _ := regexp.MatchString("arguments", curDir)
	matchTestsDir, _ := regexp.MatchString("tests", curDir)
	if match || matchArgs || matchTestsDir {
		if matchTestsDir {
			levelUp = ".."
		}
		curDir, _ = filepath.Abs(curDir + sep + levelUp + sep)
	}

	CurrDirectory = curDir
	configDir, _ := filepath.Abs(curDir + sep + CONFIG_DIR + sep)
	appConfig := configDir + sep + CONFIG_FILE
	appProdConfig := configDir + sep + PRODUCTION_FOLDER + sep + CONFIG_FILE
	if fileExists(appProdConfig) {
		appConfig = appProdConfig
	} else if !useosxt {
		appConfig = detectProdConfig(true)
	}

	return appConfig
}
开发者ID:andboson,项目名称:configlog,代码行数:34,代码来源:configlog.go


示例9: DefaultAssetPath

func DefaultAssetPath() string {
	var assetPath string
	pwd, _ := os.Getwd()
	srcdir := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist")

	// If the current working directory is the go-ethereum dir
	// assume a debug build and use the source directory as
	// asset directory.
	if pwd == srcdir {
		assetPath = path.Join(pwd, "assets")
	} else {
		switch runtime.GOOS {
		case "darwin":
			// Get Binary Directory
			exedir, _ := osext.ExecutableFolder()
			assetPath = filepath.Join(exedir, "..", "Resources")
		case "linux":
			assetPath = path.Join("usr", "share", "mist")
		case "windows":
			assetPath = path.Join(".", "assets")
		default:
			assetPath = "."
		}
	}

	// Check if the assetPath exists. If not, try the source directory
	// This happens when binary is run from outside cmd/mist directory
	if _, err := os.Stat(assetPath); os.IsNotExist(err) {
		assetPath = path.Join(srcdir, "assets")
	}

	return assetPath
}
开发者ID:CedarLogic,项目名称:go-ethereum,代码行数:33,代码来源:path.go


示例10: getData

// GetData retrieves and calculates the metrics to be displayed in the report page.
func getData(data *Info) error {
	currentFolder, err := osext.ExecutableFolder()
	if err != nil {
		log.Error("Could not retrieve current folder. Attempting to use dot(.) instead...", "error", err)
		currentFolder = "."
	}

	dbFilePath := currentFolder + "/values.db"
	db, err := sql.Open("sqlite3", dbFilePath)
	if err != nil {
		log.Crit("Failed to opend database", "error", err, "path", dbFilePath)
		return err
	}
	defer db.Close()

	rows, err := db.Query("SELECT timestamp, ping, download, upload FROM bandwidth")
	if err != nil {
		log.Crit("Could not retrieve data from database", "error", err)
		return err
	}
	defer rows.Close()

	min := 10000.0 // Unfortunately, I don't see myself with a 10000Mbit/s connection anytime soon...
	max := 0.0
	counter := 0
	average := 0.0
	data.Points = [][]interface{}{{map[string]string{"type": "datetime", "label": "Time"}, "Download", "Upload"}}

	for rows.Next() {
		var timestamp string
		var ping, download, upload float64
		rows.Scan(&timestamp, &ping, &download, &upload)

		if download < min {
			min = download
		}

		if download > max {
			max = download
		}

		average += download
		counter++

		// Timestamp is presented as YYYY-MM-DD HH:MI:SS.Milli+0000
		split := strings.Split(timestamp, " ")
		dateOnly := strings.Split(string(split[0]), "-")
		timeOnly := strings.Split(string(split[1]), ".")
		timeOnly = strings.Split(string(timeOnly[0]), ":")
		axis := fmt.Sprintf("Date(%s, %s, %s, %s, %s, %s)", dateOnly[0], dateOnly[1], dateOnly[2], timeOnly[0], timeOnly[1], timeOnly[2])

		data.Points = append(data.Points, []interface{}{axis, download, upload})
	}
	data.MinValue = min
	data.MaxValue = max
	data.AvgValue = average / float64(counter)
	data.LastValue = data.Points[len(data.Points)-1][1].(float64)

	return nil
}
开发者ID:otaviokr,项目名称:check-my-speed,代码行数:61,代码来源:handlers.go


示例11: stopRemoteMasterServer

func stopRemoteMasterServer() {
	if *serveStopConfigFile == "" {
		folderPath, err := osext.ExecutableFolder()
		if err != nil {
			log.Fatal(err)
		}
		*serveStopConfigFile = folderPath + "/.apmenv/config.toml"
		os.MkdirAll(path.Dir(*serveStopConfigFile), 0777)
	}
	ctx := &daemon.Context{
		PidFileName: path.Join(filepath.Dir(*serveStopConfigFile), "main.pid"),
		PidFilePerm: 0644,
		LogFileName: path.Join(filepath.Dir(*serveStopConfigFile), "main.log"),
		LogFilePerm: 0640,
		WorkDir:     "./",
		Umask:       027,
	}

	if ok, p, _ := isDaemonRunning(ctx); ok {
		if err := p.Signal(syscall.Signal(syscall.SIGQUIT)); err != nil {
			log.Fatalf("Failed to kill daemon %v", err)
		}
	} else {
		ctx.Release()
		log.Info("instance is not running.")
	}
}
开发者ID:topfreegames,项目名称:apm,代码行数:27,代码来源:apm.go


示例12: GetLocalConfigFile

// Get the local config file -- accounts for .app bundled procs as well
func GetLocalConfigFile() string {
	folder, err := osext.ExecutableFolder()
	if err != nil {
		panic(err)
	}
	return filepath.Join(folder, "config.json")
}
开发者ID:snapbug,项目名称:hearthreplay-client,代码行数:8,代码来源:common.go


示例13: DetectFile

func DetectFile(isServ bool) (string, bool) {
	p, e := osext.ExecutableFolder()
	u, e := user.Current()
	var homeDir string
	if e == nil {
		homeDir = u.HomeDir
	} else {
		homeDir = os.Getenv("HOME")
	}
	var name string
	if isServ {
		name = "deblocus.d5s"
	} else {
		name = "deblocus.d5c"
	}
	for _, f := range []string{name, // cwd
		filepath.Join(p, name),                 // bin
		filepath.Join(homeDir, name),           // home
		filepath.Join("/etc/deblocus", name)} { // /etc/deblocus
		if !IsNotExist(f) {
			return f, true
		}
	}
	return filepath.Join(p, name), false
}
开发者ID:carvenli,项目名称:deblocus,代码行数:25,代码来源:config.go


示例14: run

func (p *program) run() {
	logger.Infof("Service running %v.", service.Platform())

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

	if _, err := os.Stat(exePath + "/logs"); os.IsNotExist(err) {
		err = os.Mkdir(exePath+"/logs", 0766)
		if err != nil {
			log.Fatalf("error creating logs folder: %v", err)
		}
	}

	ts := time.Now().Local().Format("2006-01-02")
	f, err := os.OpenFile(exePath+"/logs/print-server-"+ts+".log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		log.Fatalf("error opening log file: %v", err)
	}
	defer f.Close()

	log.SetOutput(f)
	log.SetFlags(log.Ldate + log.Ltime + log.Lmicroseconds)

	http.HandleFunc("/print", print)
	http.HandleFunc("/", home)

	log.Printf("Server started-up and listening at %s.", *addr)
	log.Fatal(http.ListenAndServe(*addr, nil))
}
开发者ID:tan9,项目名称:print-server,代码行数:31,代码来源:print-server.go


示例15: resolveBinaryLocation

// lets find the executable on the PATH or in the fabric8 directory
func resolveBinaryLocation(executable string) string {
	path, err := exec.LookPath(executable)
	if err != nil || fileNotExist(path) {
		home := os.Getenv("HOME")
		if home == "" {
			util.Error("No $HOME environment variable found")
		}
		writeFileLocation := getFabric8BinLocation()

		// lets try in the fabric8 folder
		path = filepath.Join(writeFileLocation, executable)
		if fileNotExist(path) {
			path = executable
			// lets try in the folder where we found the gofabric8 executable
			folder, err := osext.ExecutableFolder()
			if err != nil {
				util.Errorf("Failed to find executable folder: %v\n", err)
			} else {
				path = filepath.Join(folder, executable)
				if fileNotExist(path) {
					util.Infof("Could not find executable at %v\n", path)
					path = executable
				}
			}
		}
	}
	util.Infof("using the executable %s\n", path)
	return path
}
开发者ID:fabric8io,项目名称:gofabric8,代码行数:30,代码来源:start.go


示例16: GetBlankDir

// GetBlankDir returns the path to go-bootstrap's blank directory
func GetBlankDir() (string, error) {
	executableDir, err := osext.ExecutableFolder()
	ExitOnError(err, "Cannot find go-bootstrap path")

	ret := filepath.Join(executableDir, "blank")
	if _, err = os.Stat(ret); err == nil {
		return ret, nil
	}

	base := filepath.Join("src", "github.com", "go-bootstrap", "go-bootstrap")

	// if the blank project can't be found in the executable's dir,
	// try to locate the source code, it should be there.
	// $gopath/bin/../src/github.com/go-bootstrap/go-bootstrap
	srcDir := filepath.Join(filepath.Dir(executableDir), base)
	ret = filepath.Join(srcDir, "blank")
	if _, err = os.Stat(ret); err == nil {
		return ret, nil
	}

	// As the last resort search all gopaths.
	// This is useful when executed with `go run`
	for _, gopath := range GoPaths() {
		ret = filepath.Join(filepath.Join(gopath, base), "blank")
		if _, err = os.Stat(ret); err == nil {
			return ret, nil
		}
	}

	return "", errors.New("Cannot find go-bootstrap's blank directory")
}
开发者ID:heynickc,项目名称:go-bootstrap,代码行数:32,代码来源:helpers.go


示例17: getMoonLauncher

func getMoonLauncher() *MoonLauncher {
	if moonLauncher != nil {
		return moonLauncher
	}

	moonLauncher = &MoonLauncher{
		name: "MoonDeploy",
	}

	moonLauncher.title = fmt.Sprintf("%v %v", moonLauncher.name, moondeploy.Version)

	var err error
	moonLauncher.executable, err = osext.Executable()
	if err != nil {
		panic(err)
	}

	moonLauncher.directory, err = osext.ExecutableFolder()
	if err != nil {
		panic(err)
	}

	moonLauncher.iconPathAsIco = filepath.Join(moonLauncher.directory, "moondeploy.ico")
	moonLauncher.iconPathAsPng = filepath.Join(moonLauncher.directory, "moondeploy.png")

	moonLauncher.settings = getMoonSettings()

	return moonLauncher
}
开发者ID:giancosta86,项目名称:moondeploy,代码行数:29,代码来源:launcher.go


示例18: NewRouter

func NewRouter() *mux.Router {
	var handler http.Handler

	logger := log.New("module", "web.router")
	router := mux.NewRouter().StrictSlash(true)
	for _, route := range routes {
		handler = route.HandlerFunc
		handler = Logger(handler, route.Name, logger)

		router.
			Methods(route.Method).
			Path(route.Pattern).
			Name(route.Name).
			Handler(handler)
	}

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

	handler = http.FileServer(http.Dir(currentFolder + "/html/lib/"))
	handler = http.StripPrefix("/resources/", handler)
	handler = Logger(handler, "Resources", logger)
	router.
		Methods("GET").
		PathPrefix("/resources/").
		Name("Resources").
		Handler(handler)

	return router
}
开发者ID:otaviokr,项目名称:check-my-speed,代码行数:32,代码来源:router.go


示例19: main

func main() {

	ROOT_DIR, _ = osext.ExecutableFolder()
	config.LoadConfig(ge.BuildFullPath(ROOT_DIR, "config.json"))

	GE = ge.NewGalaxyEmpires(ge.BuildFullPath(ROOT_DIR, "data"), ge.CoordinatesStruct{1, 15, 5})

	r := gin.New()
	r.Use(gin.Logger())
	r.Use(gin.Recovery())
	r.Use(middleware.Errors("", "", nil))

	debug.AssignDebugHandlers(r.Group("/debug"))

	handlers.NewAccountHandler(r.Group("/account"), GE)
	handlers.NewPlayerHandler(r.Group("/player", middleware.Authentication([]byte(config.Config.Key))), GE)
	handlers.NewPlanetHandler(r.Group("/planet", middleware.Authentication([]byte(config.Config.Key))), GE)

	r.Static("/assets", ROOT_DIR+"/web/assets")
	r.StaticFile("/", ROOT_DIR+"/web/index.html")

	if err := r.Run(":" + config.Config.Port); err != nil {
		panic(err)
	}

}
开发者ID:nazwa,项目名称:Galaxy-Empires,代码行数:26,代码来源:main.go


示例20: main

// start
func main() {
	var p Player
	folderPath, _ := osext.ExecutableFolder()
	p.client_id, _ = ioutil.ReadFile(folderPath + "/client_id.txt")
	p.MinD = 50 * 60 * 1000
	p.MaxD = 500 * 60 * 1000
	println("Please type a search term or 'x' to exit ....")
	r := bufio.NewReader(os.Stdin)
	for {
		i, _, _ := r.ReadLine()
		p.li = string(i)
		switch {
		case p.li == "x":
			p.exit()
		case p.li == "ll":
			p.showResultList()
		case strings.HasPrefix(p.li, "set "):
			p.set()
		case strings.HasPrefix(p.li, "i "):
			p.info()
		case isAllint(p.li):
			go p.killAndPlay()
		case true:
			p.searchSoundCloud()
			sort.Sort(ByLength{p.srs})
			sort.Sort(ByAge{p.srs})
			p.showResultList()
		}
	}
}
开发者ID:schomsko,项目名称:gosoundcloudplayer,代码行数:31,代码来源:soccli.go



注:本文中的github.com/kardianos/osext.ExecutableFolder函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang service.Control函数代码示例发布时间:2022-05-23
下一篇:
Golang osext.Executable函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap