本文整理汇总了Golang中github.com/astaxie/beego/utils.FileExists函数的典型用法代码示例。如果您正苦于以下问题:Golang FileExists函数的具体用法?Golang FileExists怎么用?Golang FileExists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FileExists函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
BConfig = newBConfig()
var err error
if AppPath, err = filepath.Abs(filepath.Dir(os.Args[0])); err != nil {
panic(err)
}
workPath, err := os.Getwd()
if err != nil {
panic(err)
}
appConfigPath = filepath.Join(workPath, "conf", "app.conf")
if !utils.FileExists(appConfigPath) {
appConfigPath = filepath.Join(AppPath, "conf", "app.conf")
if !utils.FileExists(appConfigPath) {
AppConfig = &beegoAppConfig{innerConfig: config.NewFakeConfig()}
return
}
}
if err = parseConfig(appConfigPath); err != nil {
panic(err)
}
if err = os.Chdir(AppPath); err != nil {
panic(err)
}
}
示例2: needCheckUpdate
func needCheckUpdate() bool {
// Does not have record for check update.
stamp, err := beego.AppConfig.Int64("app::update_check_time")
if err != nil {
return true
}
if !utils.FileExists("conf/docTree.json") || !utils.FileExists("conf/blogTree.json") ||
!utils.FileExists("conf/productTree.json") {
return true
}
return time.Unix(stamp, 0).Add(5 * time.Minute).Before(time.Now())
}
示例3: initBlogMap
func initBlogMap() {
os.Mkdir("blog", os.ModePerm)
langs := strings.Split(beego.AppConfig.String("lang::types"), "|")
for _, l := range langs {
os.Mkdir("blog/"+l, os.ModePerm)
}
if !utils.FileExists("conf/blogTree.json") {
beego.Error("models.initBlogMap -> conf/blogTree.json does not exist")
return
}
f, err := os.Open("conf/blogTree.json")
if err != nil {
beego.Error("models.initBlogMap -> load data:", err.Error())
return
}
defer f.Close()
d := json.NewDecoder(f)
err = d.Decode(&blogTree)
if err != nil {
beego.Error("models.initBlogMap -> decode data:", err.Error())
return
}
blogLock.Lock()
defer blogLock.Unlock()
blogMap = make(map[string]*docFile)
for _, v := range blogTree.Tree {
blogMap[v.Path] = getFile("blog/" + v.Path)
}
}
示例4: isSystemPackage
func isSystemPackage(pkgpath string) bool {
goroot := runtime.GOROOT()
if goroot == "" {
panic("goroot is empty, do you install Go right?")
}
wg, _ := filepath.EvalSymlinks(filepath.Join(goroot, "src", "pkg", pkgpath))
if utils.FileExists(wg) {
return true
}
//TODO(zh):support go1.4
wg, _ = filepath.EvalSymlinks(filepath.Join(goroot, "src", pkgpath))
if utils.FileExists(wg) {
return true
}
return false
}
示例5: Load
// Load return Configer
// you can load the specific config file by run mode
func Load(configFile string) (cf config.Configer, err error) {
if c, ok := configFiles[configFile]; ok {
cf = c
return
}
fullPathFile := filepath.Join("conf", beego.BConfig.RunMode, configFile)
if !utils.FileExists(fullPathFile) {
fullPathFile = filepath.Join("conf", configFile)
if !utils.FileExists(fullPathFile) {
err = errors.New(fullPathFile + " not found")
return
}
}
adapter := strings.TrimLeft(filepath.Ext(fullPathFile), ".")
cf, err = config.NewConfig(adapter, fullPathFile)
if err != nil {
configFiles[configFile] = cf
}
return
}
示例6: compareFile
func compareFile(pkgRealpath string) bool {
if !utils.FileExists(path.Join(workPath, "routers", commentFilename)) {
return true
}
if utils.FileExists(path.Join(workPath, lastupdateFilename)) {
content, err := ioutil.ReadFile(path.Join(workPath, lastupdateFilename))
if err != nil {
return true
}
json.Unmarshal(content, &pkgLastupdate)
lastupdate, err := getpathTime(pkgRealpath)
if err != nil {
return true
}
if v, ok := pkgLastupdate[pkgRealpath]; ok {
if lastupdate <= v {
return false
}
}
}
return true
}
示例7: getRouterDir
func getRouterDir(pkgRealpath string) string {
dir := filepath.Dir(pkgRealpath)
for {
d := filepath.Join(dir, "routers")
if utils.FileExists(d) {
return d
}
if r, _ := filepath.Rel(dir, AppPath); r == "." {
return d
}
// Parent dir.
dir = filepath.Dir(dir)
}
}
示例8: LoadAppConfig
// LoadAppConfig allow developer to apply a config file
func LoadAppConfig(adapterName, configPath string) error {
absConfigPath, err := filepath.Abs(configPath)
if err != nil {
return err
}
if !utils.FileExists(absConfigPath) {
return fmt.Errorf("the target config file: %s don't exist", configPath)
}
appConfigPath = absConfigPath
appConfigProvider = adapterName
return parseConfig(appConfigPath)
}
示例9: initDocMap
func initDocMap() {
// Documentation names.
docNames := make([]string, 0, 20)
docNames = append(docNames, strings.Split(
beego.AppConfig.String("app::doc_names"), "|")...)
isConfExist := utils.FileExists("conf/docTree.json")
if isConfExist {
f, err := os.Open("conf/docTree.json")
if err != nil {
beego.Error("models.initDocMap -> load data:", err.Error())
return
}
defer f.Close()
d := json.NewDecoder(f)
if err = d.Decode(&docTree); err != nil {
beego.Error("models.initDocMap -> decode data:", err.Error())
return
}
} else {
// Generate 'docTree'.
for _, v := range docNames {
docTree.Tree = append(docTree.Tree, oldDocNode{Path: v})
}
}
docLock.Lock()
defer docLock.Unlock()
docMap = make(map[string]*docFile)
langs := strings.Split(beego.AppConfig.String("lang::types"), "|")
os.Mkdir("docs", os.ModePerm)
for _, l := range langs {
os.Mkdir("docs/"+l, os.ModePerm)
for _, v := range docTree.Tree {
var fullName string
if isConfExist {
fullName = v.Path
} else {
fullName = l + "/" + v.Path
}
docMap[fullName] = getFile("docs/" + fullName)
}
}
}
示例10: get
// download src
func (b *Builder) get() (err error) {
log.Debug("start get src to:", b.srcDir)
exists := beeutils.FileExists(b.srcDir)
b.sh.Command("go", "version").Run()
if !exists {
err = b.sh.Command("go", "get", "-v", "-d", b.project).Run()
if err != nil {
return
}
}
b.sh.SetDir(b.srcDir)
if b.ref == "-" {
b.ref = "master"
}
// get code from remote
if err = b.sh.Command("git", "fetch", "origin").Run(); err != nil {
return
}
// change branch
if err = b.sh.Command("git", "checkout", "-q", b.ref).Run(); err != nil {
return
}
// update code
if err = b.sh.Command("git", "merge", "origin/"+b.ref).Run(); err != nil {
log.Warn("git merge error:", err)
//return
}
// get sha
out, err := sh.Command("git", "rev-parse", "HEAD", sh.Dir(b.srcDir)).Output()
if err != nil {
return
}
b.sha = strings.TrimSpace(string(out))
// parse .gobuild
b.rc = new(Assembly)
rcfile := "public/gobuildrc"
if b.sh.Test("f", ".gobuild") {
rcfile = filepath.Join(b.srcDir, ".gobuild")
}
data, err := ioutil.ReadFile(rcfile)
if err != nil {
return
}
err = goyaml.Unmarshal(data, b.rc)
return
}
示例11: compareFile
func compareFile(pkgRealpath string) bool {
if utils.FileExists(path.Join(AppPath, lastupdateFilename)) {
content, err := ioutil.ReadFile(path.Join(AppPath, lastupdateFilename))
if err != nil {
return true
}
json.Unmarshal(content, &pkgLastupdate)
ft, err := os.Lstat(pkgRealpath)
if err != nil {
return true
}
if v, ok := pkgLastupdate[pkgRealpath]; ok {
if ft.ModTime().UnixNano() >= v {
return false
}
}
}
return true
}
示例12: get
// download src
func (b *Builder) get() (err error) {
exists := beeutils.FileExists(b.srcDir)
b.sh.Command("date")
if !exists {
err = b.sh.Command("go", "get", "-v", "-d", b.project).Run()
if err != nil {
return
}
}
b.sh.SetDir(b.srcDir)
if b.ref == "-" {
b.ref = "master"
}
if err = b.sh.Command("git", "fetch", "origin").Run(); err != nil {
return
}
if err = b.sh.Command("git", "checkout", "-q", b.ref).Run(); err != nil {
return
}
if err = b.sh.Command("git", "merge", "origin/"+b.ref).Run(); err != nil {
return
}
out, err := sh.Command("git", "rev-parse", "HEAD", sh.Dir(b.srcDir)).Output()
if err != nil {
return
}
b.sha = strings.TrimSpace(string(out))
// parse .gobuild
b.rc = new(Assembly)
rcfile := "public/gobuildrc"
if b.sh.Test("f", ".gobuild") {
rcfile = filepath.Join(b.srcDir, ".gobuild")
}
data, err := ioutil.ReadFile(rcfile)
if err != nil {
return
}
err = goyaml.Unmarshal(data, b.rc)
return
}
示例13: Include
// Include only when the Runmode is dev will generate router file in the router/auto.go from the controller
// Include(&BankAccount{}, &OrderController{},&RefundController{},&ReceiptController{})
func (p *ControllerRegister) Include(cList ...ControllerInterface) {
if BConfig.RunMode == DEV {
skip := make(map[string]bool, 10)
for _, c := range cList {
reflectVal := reflect.ValueOf(c)
t := reflect.Indirect(reflectVal).Type()
gopath := os.Getenv("GOPATH")
if gopath == "" {
panic("you are in dev mode. So please set gopath")
}
pkgpath := ""
wgopath := filepath.SplitList(gopath)
for _, wg := range wgopath {
wg, _ = filepath.EvalSymlinks(filepath.Join(wg, "src", t.PkgPath()))
if utils.FileExists(wg) {
pkgpath = wg
break
}
}
if pkgpath != "" {
if _, ok := skip[pkgpath]; !ok {
skip[pkgpath] = true
parserPkg(pkgpath, t.PkgPath())
}
}
}
}
for _, c := range cList {
reflectVal := reflect.ValueOf(c)
t := reflect.Indirect(reflectVal).Type()
key := t.PkgPath() + ":" + t.Name()
if comm, ok := GlobalControllerRouter[key]; ok {
for _, a := range comm {
p.Add(a.Router, c, strings.Join(a.AllowHTTPMethods, ",")+":"+a.Method)
}
}
}
}
示例14: getTplDeep
func getTplDeep(root, file, parent string, t *template.Template) (*template.Template, [][]string, error) {
var fileAbsPath string
if filepath.HasPrefix(file, "../") {
fileAbsPath = filepath.Join(root, filepath.Dir(parent), file)
} else {
fileAbsPath = filepath.Join(root, file)
}
if e := utils.FileExists(fileAbsPath); !e {
panic("can't find template file:" + file)
}
data, err := ioutil.ReadFile(fileAbsPath)
if err != nil {
return nil, [][]string{}, err
}
t, err = t.New(file).Parse(string(data))
if err != nil {
return nil, [][]string{}, err
}
reg := regexp.MustCompile(BConfig.WebConfig.TemplateLeft + "[ ]*template[ ]+\"([^\"]+)\"")
allSub := reg.FindAllStringSubmatch(string(data), -1)
for _, m := range allSub {
if len(m) == 2 {
tl := t.Lookup(m[1])
if tl != nil {
continue
}
if !HasTemplateExt(m[1]) {
continue
}
t, _, err = getTplDeep(root, m[1], file, t)
if err != nil {
return nil, [][]string{}, err
}
}
}
return t, allSub, nil
}
示例15: init
func init() {
// create beego application
BeeApp = NewApp()
workPath, _ = os.Getwd()
workPath, _ = filepath.Abs(workPath)
// initialize default configurations
AppPath, _ = filepath.Abs(filepath.Dir(os.Args[0]))
AppConfigPath = filepath.Join(AppPath, "conf", "app.conf")
if workPath != AppPath {
if utils.FileExists(AppConfigPath) {
os.Chdir(AppPath)
} else {
AppConfigPath = filepath.Join(workPath, "conf", "app.conf")
}
}
AppConfigProvider = "ini"
StaticDir = make(map[string]string)
StaticDir["/static"] = "static"
StaticExtensionsToGzip = []string{".css", ".js"}
TemplateCache = make(map[string]*template.Template)
// set this to 0.0.0.0 to make this app available to externally
EnableHttpListen = true //default enable http Listen
HttpAddr = ""
HttpPort = 8080
HttpsPort = 10443
AppName = "beego"
RunMode = "dev" //default runmod
AutoRender = true
RecoverPanic = true
ViewsPath = "views"
SessionOn = false
SessionProvider = "memory"
SessionName = "beegosessionID"
SessionGCMaxLifetime = 3600
SessionSavePath = ""
SessionCookieLifeTime = 0 //set cookie default is the brower life
SessionAutoSetCookie = true
UseFcgi = false
UseStdIo = false
MaxMemory = 1 << 26 //64MB
EnableGzip = false
HttpServerTimeOut = 0
ErrorsShow = true
XSRFKEY = "beegoxsrf"
XSRFExpire = 0
TemplateLeft = "{{"
TemplateRight = "}}"
BeegoServerName = "beegoServer:" + VERSION
EnableAdmin = false
AdminHttpAddr = "127.0.0.1"
AdminHttpPort = 8088
FlashName = "BEEGO_FLASH"
FlashSeperator = "BEEGOFLASH"
RouterCaseSensitive = true
runtime.GOMAXPROCS(runtime.NumCPU())
// init BeeLogger
BeeLogger = logs.NewLogger(10000)
err := BeeLogger.SetLogger("console", "")
if err != nil {
fmt.Println("init console log error:", err)
}
SetLogFuncCall(true)
err = ParseConfig()
if err != nil && os.IsNotExist(err) {
// for init if doesn't have app.conf will not panic
ac := config.NewFakeConfig()
AppConfig = &beegoAppConfig{ac}
Warning(err)
}
}