本文整理汇总了Golang中github.com/astaxie/beego/utils.FileExists函数的典型用法代码示例。如果您正苦于以下问题:Golang FileExists函数的具体用法?Golang FileExists怎么用?Golang FileExists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FileExists函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
}
开发者ID:astaxie,项目名称:beego,代码行数:25,代码来源:config.go
示例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())
}
开发者ID:flying99999,项目名称:beeweb,代码行数:14,代码来源:models.go
示例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)
}
}
开发者ID:flying99999,项目名称:beeweb,代码行数:34,代码来源:models.go
示例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
}
开发者ID:kyawmyintthein,项目名称:bee,代码行数:18,代码来源:g_docs.go
示例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
}
开发者ID:coseyo,项目名称:beeconfig,代码行数:22,代码来源:config.go
示例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
}
开发者ID:jiajie999,项目名称:beego,代码行数:22,代码来源:parser.go
示例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)
}
}
开发者ID:Hepri,项目名称:beego,代码行数:15,代码来源:parser.go
示例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)
}
开发者ID:chaws,项目名称:beego,代码行数:16,代码来源:config.go
示例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)
}
}
}
开发者ID:flying99999,项目名称:beeweb,代码行数:48,代码来源:models.go
示例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
}
开发者ID:matm,项目名称:gobuild,代码行数:48,代码来源:build_get.go
示例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
}
开发者ID:roson9527,项目名称:beego,代码行数:19,代码来源:parser.go
示例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
}
开发者ID:kaisne,项目名称:gobuild,代码行数:42,代码来源:build_get.go
示例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)
}
}
}
}
开发者ID:CodingDance,项目名称:harbor,代码行数:41,代码来源:router.go
示例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
}
开发者ID:GrimTheReaper,项目名称:beego,代码行数:37,代码来源:template.go
示例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)
}
}
开发者ID:Wishing-Wall,项目名称:wishingwall,代码行数:100,代码来源:config.go
示例16: ParseConfig
// ParseConfig parsed default config file.
// now only support ini, next will support json.
func ParseConfig() (err error) {
if AppConfigPath == "" {
if utils.FileExists(filepath.Join("conf", "app.conf")) {
AppConfigPath = filepath.Join("conf", "app.conf")
} else {
AppConfig = &beegoAppConfig{config.NewFakeConfig()}
return
}
}
AppConfig, err = newAppConfig(AppConfigProvider, AppConfigPath)
if err != nil {
return err
}
// set the runmode first
if envRunMode := os.Getenv("BEEGO_RUNMODE"); envRunMode != "" {
BConfig.RunMode = envRunMode
} else if runmode := AppConfig.String("RunMode"); runmode != "" {
BConfig.RunMode = runmode
}
BConfig.AppName = AppConfig.DefaultString("AppName", BConfig.AppName)
BConfig.RecoverPanic = AppConfig.DefaultBool("RecoverPanic", BConfig.RecoverPanic)
BConfig.RouterCaseSensitive = AppConfig.DefaultBool("RouterCaseSensitive", BConfig.RouterCaseSensitive)
BConfig.ServerName = AppConfig.DefaultString("ServerName", BConfig.ServerName)
BConfig.EnableGzip = AppConfig.DefaultBool("EnableGzip", BConfig.EnableGzip)
BConfig.EnableErrorsShow = AppConfig.DefaultBool("EnableErrorsShow", BConfig.EnableErrorsShow)
BConfig.CopyRequestBody = AppConfig.DefaultBool("CopyRequestBody", BConfig.CopyRequestBody)
BConfig.MaxMemory = AppConfig.DefaultInt64("MaxMemory", BConfig.MaxMemory)
BConfig.Listen.Graceful = AppConfig.DefaultBool("Graceful", BConfig.Listen.Graceful)
BConfig.Listen.HTTPAddr = AppConfig.String("HTTPAddr")
BConfig.Listen.HTTPPort = AppConfig.DefaultInt("HTTPPort", BConfig.Listen.HTTPPort)
BConfig.Listen.ListenTCP4 = AppConfig.DefaultBool("ListenTCP4", BConfig.Listen.ListenTCP4)
BConfig.Listen.EnableHTTP = AppConfig.DefaultBool("EnableHTTP", BConfig.Listen.EnableHTTP)
BConfig.Listen.EnableHTTPS = AppConfig.DefaultBool("EnableHTTPS", BConfig.Listen.EnableHTTPS)
BConfig.Listen.HTTPSAddr = AppConfig.DefaultString("HTTPSAddr", BConfig.Listen.HTTPSAddr)
BConfig.Listen.HTTPSPort = AppConfig.DefaultInt("HTTPSPort", BConfig.Listen.HTTPSPort)
BConfig.Listen.HTTPSCertFile = AppConfig.DefaultString("HTTPSCertFile", BConfig.Listen.HTTPSCertFile)
BConfig.Listen.HTTPSKeyFile = AppConfig.DefaultString("HTTPSKeyFile", BConfig.Listen.HTTPSKeyFile)
BConfig.Listen.EnableAdmin = AppConfig.DefaultBool("EnableAdmin", BConfig.Listen.EnableAdmin)
BConfig.Listen.AdminAddr = AppConfig.DefaultString("AdminAddr", BConfig.Listen.AdminAddr)
BConfig.Listen.AdminPort = AppConfig.DefaultInt("AdminPort", BConfig.Listen.AdminPort)
BConfig.Listen.EnableFcgi = AppConfig.DefaultBool("EnableFcgi", BConfig.Listen.EnableFcgi)
BConfig.Listen.EnableStdIo = AppConfig.DefaultBool("EnableStdIo", BConfig.Listen.EnableStdIo)
BConfig.Listen.ServerTimeOut = AppConfig.DefaultInt64("ServerTimeOut", BConfig.Listen.ServerTimeOut)
BConfig.WebConfig.AutoRender = AppConfig.DefaultBool("AutoRender", BConfig.WebConfig.AutoRender)
BConfig.WebConfig.ViewsPath = AppConfig.DefaultString("ViewsPath", BConfig.WebConfig.ViewsPath)
BConfig.WebConfig.DirectoryIndex = AppConfig.DefaultBool("DirectoryIndex", BConfig.WebConfig.DirectoryIndex)
BConfig.WebConfig.FlashName = AppConfig.DefaultString("FlashName", BConfig.WebConfig.FlashName)
BConfig.WebConfig.FlashSeparator = AppConfig.DefaultString("FlashSeparator", BConfig.WebConfig.FlashSeparator)
BConfig.WebConfig.EnableDocs = AppConfig.DefaultBool("EnableDocs", BConfig.WebConfig.EnableDocs)
BConfig.WebConfig.XSRFKey = AppConfig.DefaultString("XSRFKEY", BConfig.WebConfig.XSRFKey)
BConfig.WebConfig.EnableXSRF = AppConfig.DefaultBool("EnableXSRF", BConfig.WebConfig.EnableXSRF)
BConfig.WebConfig.XSRFExpire = AppConfig.DefaultInt("XSRFExpire", BConfig.WebConfig.XSRFExpire)
BConfig.WebConfig.TemplateLeft = AppConfig.DefaultString("TemplateLeft", BConfig.WebConfig.TemplateLeft)
BConfig.WebConfig.TemplateRight = AppConfig.DefaultString("TemplateRight", BConfig.WebConfig.TemplateRight)
BConfig.WebConfig.Session.SessionOn = AppConfig.DefaultBool("SessionOn", BConfig.WebConfig.Session.SessionOn)
BConfig.WebConfig.Session.SessionProvider = AppConfig.DefaultString("SessionProvider", BConfig.WebConfig.Session.SessionProvider)
BConfig.WebConfig.Session.SessionName = AppConfig.DefaultString("SessionName", BConfig.WebConfig.Session.SessionName)
BConfig.WebConfig.Session.SessionProviderConfig = AppConfig.DefaultString("SessionProviderConfig", BConfig.WebConfig.Session.SessionProviderConfig)
BConfig.WebConfig.Session.SessionGCMaxLifetime = AppConfig.DefaultInt64("SessionGCMaxLifetime", BConfig.WebConfig.Session.SessionGCMaxLifetime)
BConfig.WebConfig.Session.SessionCookieLifeTime = AppConfig.DefaultInt("SessionCookieLifeTime", BConfig.WebConfig.Session.SessionCookieLifeTime)
BConfig.WebConfig.Session.SessionAutoSetCookie = AppConfig.DefaultBool("SessionAutoSetCookie", BConfig.WebConfig.Session.SessionAutoSetCookie)
BConfig.WebConfig.Session.SessionDomain = AppConfig.DefaultString("SessionDomain", BConfig.WebConfig.Session.SessionDomain)
if sd := AppConfig.String("StaticDir"); sd != "" {
for k := range BConfig.WebConfig.StaticDir {
delete(BConfig.WebConfig.StaticDir, k)
}
sds := strings.Fields(sd)
for _, v := range sds {
if url2fsmap := strings.SplitN(v, ":", 2); len(url2fsmap) == 2 {
BConfig.WebConfig.StaticDir["/"+strings.TrimRight(url2fsmap[0], "/")] = url2fsmap[1]
} else {
BConfig.WebConfig.StaticDir["/"+strings.TrimRight(url2fsmap[0], "/")] = url2fsmap[0]
}
}
}
if sgz := AppConfig.String("StaticExtensionsToGzip"); sgz != "" {
extensions := strings.Split(sgz, ",")
fileExts := []string{}
for _, ext := range extensions {
ext = strings.TrimSpace(ext)
if ext == "" {
continue
}
if !strings.HasPrefix(ext, ".") {
ext = "." + ext
}
fileExts = append(fileExts, ext)
}
if len(fileExts) > 0 {
BConfig.WebConfig.StaticExtensionsToGzip = fileExts
}
}
return nil
}
开发者ID:ysqi,项目名称:beego,代码行数:99,代码来源:config.go
示例17: Run
// Run beego application.
func (app *App) Run() {
addr := HttpAddr
if HttpPort != 0 {
addr = fmt.Sprintf("%s:%d", HttpAddr, HttpPort)
}
var (
err error
l net.Listener
)
endRunning := make(chan bool, 1)
if UseFcgi {
if UseStdIo {
err = fcgi.Serve(nil, app.Handlers) // standard I/O
if err == nil {
BeeLogger.Info("Use FCGI via standard I/O")
} else {
BeeLogger.Info("Cannot use FCGI via standard I/O", err)
}
} else {
if HttpPort == 0 {
// remove the Socket file before start
if utils.FileExists(addr) {
os.Remove(addr)
}
l, err = net.Listen("unix", addr)
} else {
l, err = net.Listen("tcp", addr)
}
if err != nil {
BeeLogger.Critical("Listen: ", err)
}
err = fcgi.Serve(l, app.Handlers)
}
} else {
app.Server.Addr = addr
app.Server.Handler = app.Handlers
app.Server.ReadTimeout = time.Duration(HttpServerTimeOut) * time.Second
app.Server.WriteTimeout = time.Duration(HttpServerTimeOut) * time.Second
if EnableHttpTLS {
go func() {
time.Sleep(20 * time.Microsecond)
if HttpsPort != 0 {
app.Server.Addr = fmt.Sprintf("%s:%d", HttpAddr, HttpsPort)
}
BeeLogger.Info("https server Running on %s", app.Server.Addr)
err := app.Server.ListenAndServeTLS(HttpCertFile, HttpKeyFile)
if err != nil {
BeeLogger.Critical("ListenAndServeTLS: ", err)
time.Sleep(100 * time.Microsecond)
endRunning <- true
}
}()
}
if EnableHttpListen {
go func() {
app.Server.Addr = addr
BeeLogger.Info("http server Running on %s", app.Server.Addr)
if ListenTCP4 && HttpAddr == "" {
ln, err := net.Listen("tcp4", app.Server.Addr)
if err != nil {
BeeLogger.Critical("ListenAndServe: ", err)
time.Sleep(100 * time.Microsecond)
endRunning <- true
return
}
err = app.Server.Serve(ln)
if err != nil {
BeeLogger.Critical("ListenAndServe: ", err)
time.Sleep(100 * time.Microsecond)
endRunning <- true
return
}
} else {
err := app.Server.ListenAndServe()
if err != nil {
BeeLogger.Critical("ListenAndServe: ", err)
time.Sleep(100 * time.Microsecond)
endRunning <- true
}
}
}()
}
}
<-endRunning
}
开发者ID:jamesbjackson,项目名称:seagull,代码行数:92,代码来源:app.go
示例18: serverStaticRouter
func serverStaticRouter(ctx *context.Context) {
requestPath := path.Clean(ctx.Input.Request.URL.Path)
for prefix, staticDir := range StaticDir {
if len(prefix) == 0 {
continue
}
if requestPath == "/favicon.ico" {
file := path.Join(staticDir, requestPath)
if utils.FileExists(file) {
http.ServeFile(ctx.ResponseWriter, ctx.Request, file)
return
}
}
if strings.HasPrefix(requestPath, prefix) {
if len(requestPath) > len(prefix) && requestPath[len(prefix)] != '/' {
continue
}
file := path.Join(staticDir, requestPath[len(prefix):])
finfo, err := os.Stat(file)
if err != nil {
if RunMode == "dev" {
Warn(err)
}
http.NotFound(ctx.ResponseWriter, ctx.Request)
return
}
//if the request is dir and DirectoryIndex is false then
if finfo.IsDir() && !DirectoryIndex {
middleware.Exception("403", ctx.ResponseWriter, ctx.Request, "403 Forbidden")
return
}
//This block obtained from (https://github.com/smithfox/beego) - it should probably get merged into astaxie/beego after a pull request
isStaticFileToCompress := false
if StaticExtensionsToGzip != nil && len(StaticExtensionsToGzip) > 0 {
for _, statExtension := range StaticExtensionsToGzip {
if strings.HasSuffix(strings.ToLower(file), strings.ToLower(statExtension)) {
isStaticFileToCompress = true
break
}
}
}
if isStaticFileToCompress {
var contentEncoding string
if EnableGzip {
contentEncoding = getAcceptEncodingZip(ctx.Request)
}
memzipfile, err := openMemZipFile(file, contentEncoding)
if err != nil {
return
}
if contentEncoding == "gzip" {
ctx.Output.Header("Content-Encoding", "gzip")
} else if contentEncoding == "deflate" {
ctx.Output.Header("Content-Encoding", "deflate")
} else {
ctx.Output.Header("Content-Length", strconv.FormatInt(finfo.Size(), 10))
}
http.ServeContent(ctx.ResponseWriter, ctx.Request, file, finfo.ModTime(), memzipfile)
} else {
http.ServeFile(ctx.ResponseWriter, ctx.Request, file)
}
return
}
}
}
开发者ID:4eek,项目名称:beego,代码行数:71,代码来源:staticfile.go
示例19: init
func init() {
AppPath, _ = filepath.Abs(filepath.Dir(os.Args[0]))
os.Chdir(AppPath)
BConfig = &Config{
AppName: "beego",
RunMode: DEV,
RouterCaseSensitive: true,
ServerName: "beegoServer:" + VERSION,
RecoverPanic: true,
CopyRequestBody: false,
EnableGzip: false,
MaxMemory: 1 << 26, //64MB
EnableErrorsShow: true,
Listen: Listen{
Graceful: false,
ServerTimeOut: 0,
ListenTCP4: false,
EnableHTTP: true,
HTTPAddr: "",
HTTPPort: 8080,
EnableHTTPS: false,
HTTPSAddr: "",
HTTPSPort: 10443,
HTTPSCertFile: "",
HTTPSKeyFile: "",
EnableAdmin: false,
AdminAddr: "",
AdminPort: 8088,
EnableFcgi: false,
EnableStdIo: false,
},
WebConfig: WebConfig{
AutoRender: true,
EnableDocs: false,
FlashName: "BEEGO_FLASH",
FlashSeparator: "BEEGOFLASH",
DirectoryIndex: false,
StaticDir: map[string]string{"/static": "static"},
StaticExtensionsToGzip: []string{".css", ".js"},
TemplateLeft: "{{",
TemplateRight: "}}",
ViewsPath: "views",
EnableXSRF: false,
XSRFKey: "beegoxsrf",
XSRFExpire: 0,
Session: SessionConfig{
SessionOn: false,
SessionProvider: "memory",
SessionName: "beegosessionID",
SessionGCMaxLifetime: 3600,
SessionProviderConfig: "",
SessionCookieLifeTime: 0, //set cookie default is the browser life
SessionAutoSetCookie: true,
SessionDomain: "",
},
},
Log: LogConfig{
AccessLogs: false,
FileLineNum: true,
Outputs: map[string]string{"console": ""},
},
}
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)
}
}
开发者ID:GuyCheung,项目名称:beego,代码行数:75,代码来源:config.go
示例20: ServeHTTP
//.........这里部分代码省略.........
}
}
}
}
}
return false
}
// session init
if SessionOn {
context.Input.CruSession = GlobalSessions.SessionStart(w, r)
defer func() {
context.Input.CruSession.SessionRelease(w)
}()
}
if !utils.InSlice(strings.ToLower(r.Method), HTTPMETHOD) {
http.Error(w, "Method Not Allowed", 405)
goto Admin
}
if do_filter(BeforeRouter) {
goto Admin
}
//static file server
for prefix, staticDir := range StaticDir {
if len(prefix) == 0 {
continue
}
if r.URL.Path == "/favicon.ico" {
file := path.Join(staticDir, r.URL.Path)
if utils.FileExists(file) {
http.ServeFile(w, r, file)
w.started = true
goto Admin
}
}
if strings.HasPrefix(r.URL.Path, prefix) {
if len(r.URL.Path) > len(prefix) && r.URL.Path[len(prefix)] != '/' {
continue
}
if r.URL.Path == prefix && prefix[len(prefix)-1] != '/' {
http.Redirect(rw, r, r.URL.Path+"/", 302)
goto Admin
}
file := path.Join(staticDir, r.URL.Path[len(prefix):])
finfo, err := os.Stat(file)
if err != nil {
if RunMode == "dev" {
Warn(err)
}
http.NotFound(w, r)
goto Admin
}
//if the request is dir and DirectoryIndex is false then
if finfo.IsDir() && !DirectoryIndex {
middleware.Exception("403", rw, r, "403 Forbidden")
goto Admin
}
//This block obtained from (https://github.com/smithfox/beego) - it should probably get merged into astaxie/beego after a pull request
isStaticFileToCompress := false
if StaticExtensionsToGzip != nil && len(StaticExtensionsToGzip) > 0 {
for _, statExtension := range StaticExtensionsToGzip {
开发者ID:kylemcc,项目名称:beego,代码行数:67,代码来源:router.go
注:本文中的github.com/astaxie/beego/utils.FileExists函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论