当前位置: 首页>>代码示例>>Golang>>正文


Golang osext.ExecutableFolder函数代码示例

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


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


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