本文整理汇总了Golang中github.com/qiniu/log.Fatalf函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatalf函数的具体用法?Golang Fatalf怎么用?Golang Fatalf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatalf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: newCacheService
func newCacheService() {
CacheAdapter = Cfg.MustValue("cache", "ADAPTER", "memory")
if EnableRedis {
log.Info("Redis Enabled")
}
if EnableMemcache {
log.Info("Memcache Enabled")
}
switch CacheAdapter {
case "memory":
CacheConfig = fmt.Sprintf(`{"interval":%d}`, Cfg.MustInt("cache", "INTERVAL", 60))
case "redis", "memcache":
CacheConfig = fmt.Sprintf(`{"conn":"%s"}`, Cfg.MustValue("cache", "HOST"))
default:
qlog.Fatalf("Unknown cache adapter: %s\n", CacheAdapter)
}
var err error
Cache, err = cache.NewCache(CacheAdapter, CacheConfig)
if err != nil {
qlog.Fatalf("Init cache system failed, adapter: %s, config: %s, %v\n",
CacheAdapter, CacheConfig, err)
}
log.Info("Cache Service Enabled")
}
开发者ID:Julianzz,项目名称:gogs,代码行数:27,代码来源:conf.go
示例2: main
func main() {
configfn := "nameserver.conf"
data, err := ioutil.ReadFile(configfn)
if err != nil {
log.Fatalf("server: cannot load configuration file[%s] (%v)", configfn, err)
}
var conf config.Server
if _, err := toml.Decode(string(data), &conf); err != nil {
log.Fatalf("server: configuration file[%s] is not valid (%v)", configfn, err)
}
server := NewServer()
for i, v := range conf.Disks {
log.Infof("Adding %v to disks", v)
server.registeredDisks = append(server.registeredDisks, &conf.Disks[i])
}
log.Infof("server: starting server...")
lis, err := net.Listen("tcp", net.JoinHostPort(conf.Bind, conf.Port))
if err != nil {
log.Fatalf("server: failed to listen: %v", err)
}
log.Infof("server: listening on %s", net.JoinHostPort(conf.Bind, conf.Port))
s := grpc.NewServer()
pb.RegisterNameServer(s, server)
log.Infof("server: ready to serve clients")
s.Serve(lis)
}
开发者ID:yichengq,项目名称:nameserver,代码行数:31,代码来源:main.go
示例3: LoadRepoConfig
func LoadRepoConfig() {
workDir, err := base.ExecDir()
if err != nil {
qlog.Fatalf("Fail to get work directory: %s\n", err)
}
// Load .gitignore and license files.
types := []string{"gitignore", "license"}
typeFiles := make([][]string, 2)
for i, t := range types {
cfgPath := filepath.Join(workDir, "conf", t)
files, err := com.StatDir(cfgPath)
if err != nil {
qlog.Fatalf("Fail to get default %s files: %v\n", t, err)
}
cfgPath = filepath.Join(workDir, "custom/conf/gitignore")
if com.IsDir(cfgPath) {
customFiles, err := com.StatDir(cfgPath)
if err != nil {
qlog.Fatalf("Fail to get custom %s files: %v\n", t, err)
}
for _, f := range customFiles {
if !com.IsSliceContainsStr(files, f) {
files = append(files, f)
}
}
}
typeFiles[i] = files
}
LanguageIgns = typeFiles[0]
Licenses = typeFiles[1]
}
开发者ID:j20,项目名称:gogs,代码行数:34,代码来源:repo.go
示例4: newLogService
func newLogService() {
log.Info("%s %s", AppName, AppVer)
// Get and check log mode.
LogModes = strings.Split(Cfg.MustValue("log", "MODE", "console"), ",")
LogConfigs = make([]string, len(LogModes))
for i, mode := range LogModes {
mode = strings.TrimSpace(mode)
modeSec := "log." + mode
if _, err := Cfg.GetSection(modeSec); err != nil {
qlog.Fatalf("Unknown log mode: %s\n", mode)
}
// Log level.
levelName := Cfg.MustValue("log."+mode, "LEVEL", "Trace")
level, ok := logLevels[levelName]
if !ok {
qlog.Fatalf("Unknown log level: %s\n", levelName)
}
// Generate log configuration.
switch mode {
case "console":
LogConfigs[i] = fmt.Sprintf(`{"level":%s}`, level)
case "file":
logPath := Cfg.MustValue(modeSec, "FILE_NAME", "log/gogs.log")
os.MkdirAll(path.Dir(logPath), os.ModePerm)
LogConfigs[i] = fmt.Sprintf(
`{"level":%s,"filename":"%s","rotate":%v,"maxlines":%d,"maxsize":%d,"daily":%v,"maxdays":%d}`, level,
logPath,
Cfg.MustBool(modeSec, "LOG_ROTATE", true),
Cfg.MustInt(modeSec, "MAX_LINES", 1000000),
1<<uint(Cfg.MustInt(modeSec, "MAX_SIZE_SHIFT", 28)),
Cfg.MustBool(modeSec, "DAILY_ROTATE", true),
Cfg.MustInt(modeSec, "MAX_DAYS", 7))
case "conn":
LogConfigs[i] = fmt.Sprintf(`{"level":"%s","reconnectOnMsg":%v,"reconnect":%v,"net":"%s","addr":"%s"}`, level,
Cfg.MustBool(modeSec, "RECONNECT_ON_MSG", false),
Cfg.MustBool(modeSec, "RECONNECT", false),
Cfg.MustValue(modeSec, "PROTOCOL", "tcp"),
Cfg.MustValue(modeSec, "ADDR", ":7020"))
case "smtp":
LogConfigs[i] = fmt.Sprintf(`{"level":"%s","username":"%s","password":"%s","host":"%s","sendTos":"%s","subject":"%s"}`, level,
Cfg.MustValue(modeSec, "USER", "[email protected]"),
Cfg.MustValue(modeSec, "PASSWD", "******"),
Cfg.MustValue(modeSec, "HOST", "127.0.0.1:25"),
Cfg.MustValue(modeSec, "RECEIVERS", "[]"),
Cfg.MustValue(modeSec, "SUBJECT", "Diagnostic message from serve"))
case "database":
LogConfigs[i] = fmt.Sprintf(`{"level":"%s","driver":"%s","conn":"%s"}`, level,
Cfg.MustValue(modeSec, "Driver"),
Cfg.MustValue(modeSec, "CONN"))
}
log.NewLogger(Cfg.MustInt64("log", "BUFFER_LEN", 10000), mode, LogConfigs[i])
log.Info("Log Mode: %s(%s)", strings.Title(mode), levelName)
}
}
开发者ID:j20,项目名称:gogs,代码行数:58,代码来源:conf.go
示例5: main
func main() {
configfn := flag.String("config", "default.conf", "location of configuration file")
flag.Parse()
data, err := ioutil.ReadFile(*configfn)
if err != nil {
log.Fatalf("server: cannot load configuration file[%s] (%v)", *configfn, err)
}
var conf config.Server
if _, err := toml.Decode(string(data), &conf); err != nil {
log.Fatalf("server: configuration file[%s] is not valid (%v)", *configfn, err)
}
// default is that cfs is bootstrapped using docker
cname, err := detectDockerContainer()
if err != nil {
log.Printf("server: failed to detect docker container (%v)", err)
} else {
stats.SetContainerName(cname)
log.Printf("server: detect docker container %q", cname)
}
log.Infof("server: starting server...")
lis, err := net.Listen("tcp", net.JoinHostPort(conf.Bind, conf.Port))
if err != nil {
log.Fatalf("server: failed to listen: %v", err)
}
log.Infof("server: listening on %s", net.JoinHostPort(conf.Bind, conf.Port))
cfs := NewServer()
for _, d := range conf.Disks {
err = cfs.AddDisk(d.Name, d.Root)
if err != nil {
log.Fatalf("server: failed to add disk (%v)", err)
}
}
// 0x1234 is the client ID for cfsctl, and its quota is 10 req/sec.
enforce.SetQuota(0x1234, 10)
// TODO report with influxSinker
stats.Report(nil, 3*time.Second)
s := grpc.NewServer()
pb.RegisterCfsServer(s, cfs)
pb.RegisterStatsServer(s, stats.Server())
log.Infof("server: ready to serve clients")
s.Serve(lis)
}
开发者ID:wangtuanjie,项目名称:cfs,代码行数:53,代码来源:main.go
示例6: init
func init() {
var err error
if appPath, err = exePath(); err != nil {
qlog.Fatalf("publickey.init(fail to get app path): %v\n", err)
}
// Determine and create .ssh path.
SshPath = filepath.Join(homeDir(), ".ssh")
if err = os.MkdirAll(SshPath, os.ModePerm); err != nil {
qlog.Fatalf("publickey.init(fail to create SshPath(%s)): %v\n", SshPath, err)
}
}
开发者ID:hilerchyn,项目名称:gogs,代码行数:13,代码来源:publickey.go
示例7: NewRepoContext
func NewRepoContext() {
zip.Verbose = false
// Check if server has basic git setting.
stdout, stderr, err := com.ExecCmd("git", "config", "--get", "user.name")
if strings.Contains(stderr, "fatal:") {
qlog.Fatalf("repo.NewRepoContext(fail to get git user.name): %s", stderr)
} else if err != nil || len(strings.TrimSpace(stdout)) == 0 {
if _, stderr, err = com.ExecCmd("git", "config", "--global", "user.email", "[email protected]"); err != nil {
qlog.Fatalf("repo.NewRepoContext(fail to set git user.email): %s", stderr)
} else if _, stderr, err = com.ExecCmd("git", "config", "--global", "user.name", "Gogs"); err != nil {
qlog.Fatalf("repo.NewRepoContext(fail to set git user.name): %s", stderr)
}
}
}
开发者ID:j20,项目名称:gogs,代码行数:15,代码来源:repo.go
示例8: newSessionService
func newSessionService() {
SessionProvider = Cfg.MustValue("session", "PROVIDER", "memory")
SessionConfig = new(session.Config)
SessionConfig.ProviderConfig = Cfg.MustValue("session", "PROVIDER_CONFIG")
SessionConfig.CookieName = Cfg.MustValue("session", "COOKIE_NAME", "i_like_gogits")
SessionConfig.CookieSecure = Cfg.MustBool("session", "COOKIE_SECURE")
SessionConfig.EnableSetCookie = Cfg.MustBool("session", "ENABLE_SET_COOKIE", true)
SessionConfig.GcIntervalTime = Cfg.MustInt64("session", "GC_INTERVAL_TIME", 86400)
SessionConfig.SessionLifeTime = Cfg.MustInt64("session", "SESSION_LIFE_TIME", 86400)
SessionConfig.SessionIDHashFunc = Cfg.MustValue("session", "SESSION_ID_HASHFUNC", "sha1")
SessionConfig.SessionIDHashKey = Cfg.MustValue("session", "SESSION_ID_HASHKEY")
if SessionProvider == "file" {
os.MkdirAll(path.Dir(SessionConfig.ProviderConfig), os.ModePerm)
}
var err error
SessionManager, err = session.NewManager(SessionProvider, *SessionConfig)
if err != nil {
qlog.Fatalf("Init session system failed, provider: %s, %v\n",
SessionProvider, err)
}
log.Info("Session Service Enabled")
}
开发者ID:Julianzz,项目名称:gogs,代码行数:26,代码来源:conf.go
示例9: Send
func (s *httpSender) Send(events []Event) error {
if len(events) == 0 {
return nil
} else if len(events) > MaxBatchSize {
return ErrTooManyEvents
}
pr, pw := io.Pipe()
go func() {
err := json.NewEncoder(pw).Encode(events)
pw.CloseWithError(err)
}()
defer pr.Close()
req, err := http.NewRequest("POST", s.remote, pr)
if err != nil {
log.Fatalf("http.NewRequest %s failed - %v", s.remote, err)
}
req.Header.Add("Content-type", "application/json; charset=UTF-8")
resp, err := s.http.Do(req)
if err != nil {
return &httpErr{err, 0}
} else if resp.StatusCode != 200 {
return &httpErr{nil, resp.StatusCode}
}
defer resp.Body.Close()
return nil
}
开发者ID:dckit,项目名称:dccli,代码行数:31,代码来源:send.go
示例10: setUpClient
func setUpClient() *client.Client {
// Set up a connection to the server.
c, err := client.New(address)
if err != nil {
log.Fatalf("Cannot create cfs client: %v", err)
}
return c
}
开发者ID:missmayo,项目名称:cfs,代码行数:8,代码来源:cfs_command.go
示例11: actionStartServer
func actionStartServer(c *cli.Context) error {
suv, hdlr, err := newSupervisorHandler()
if err != nil {
log.Fatal(err)
}
auth := cfg.Server.HttpAuth
if auth.Enabled {
hdlr = httpauth.SimpleBasicAuth(auth.User, auth.Password)(hdlr)
}
http.Handle("/", hdlr)
addr := cfg.Server.Addr
if c.Bool("foreground") {
suv.AutoStartPrograms()
log.Printf("server listen on %v", addr)
log.Fatal(http.ListenAndServe(addr, nil))
} else {
if checkServerStatus() == nil {
fmt.Println("server is already running")
return nil
}
logPath := filepath.Join(defaultConfigDir, "gosuv.log")
logFd, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
log.Fatalf("create file %s failed: %v", logPath, err)
}
cmd := exec.Command(os.Args[0], "start-server", "-f")
cmd.Stdout = logFd
cmd.Stderr = logFd
err = cmd.Start()
if err != nil {
log.Fatal(err)
}
select {
case err = <-GoFunc(cmd.Wait):
log.Fatalf("server started failed, %v", err)
case <-time.After(200 * time.Millisecond):
showAddr := addr
if strings.HasPrefix(addr, ":") {
showAddr = "0.0.0.0" + addr
}
fmt.Printf("server started, listening on %s\n", showAddr)
}
}
return nil
}
开发者ID:codeskyblue,项目名称:gosuv,代码行数:46,代码来源:gosuv.go
示例12: handleWrite
func handleWrite(ctx context.Context, c *client.Client) error {
n, err := c.Write(ctx, writeName, writeOffset, []byte(writeData), writeAppend)
if err != nil {
log.Fatalf("Write err (%v)", err)
}
log.Infof("%d bytes written to %s at offset %d", n, writeName, writeOffset)
return nil
}
开发者ID:missmayo,项目名称:cfs,代码行数:9,代码来源:write_command.go
示例13: handleRename
func handleRename(ctx context.Context, c *client.Client) error {
err := c.Rename(ctx, renameOld, renameNew)
if err != nil {
log.Fatalf("Rename err (%v)", err)
}
log.Infof("rename %s into %s", renameOld, renameNew)
return nil
}
开发者ID:missmayo,项目名称:cfs,代码行数:9,代码来源:rename_command.go
示例14: handleMkdir
func handleMkdir(ctx context.Context, c *client.Client) error {
err := c.Mkdir(ctx, mkdirName, mkdirAll)
if err != nil {
log.Fatalf("Mkdir err (%v)", err)
}
fmt.Printf("mkdir %s succeeded\n", mkdirName)
return nil
}
开发者ID:missmayo,项目名称:cfs,代码行数:9,代码来源:mkdir_command.go
示例15: handleRead
func handleRead(ctx context.Context, c *client.Client) error {
_, data, _, err := c.Read(ctx, readName, readOffset, readLen, readExpChecksum)
if err != nil {
log.Fatalf("Read err (%v)", err)
}
log.Info(string(data))
return nil
}
开发者ID:missmayo,项目名称:cfs,代码行数:9,代码来源:read_command.go
示例16: handleRemove
func handleRemove(ctx context.Context, c *client.Client) error {
err := c.Remove(ctx, removeName, removeAll)
if err != nil {
log.Fatalf("Read err (%v)", err)
}
log.Info("remove succeeded")
return nil
}
开发者ID:missmayo,项目名称:cfs,代码行数:9,代码来源:remove_command.go
示例17: AddHandler
func (f *FSM) AddHandler(state FSMState, event FSMEvent, hdlr FSMHandler) *FSM {
_, ok := f.handlers[state]
if !ok {
f.handlers[state] = make(map[FSMEvent]FSMHandler)
}
if _, ok = f.handlers[state][event]; ok {
log.Fatalf("set twice for state(%s) event(%s)", state, event)
}
f.handlers[state][event] = hdlr
return f
}
开发者ID:codeskyblue,项目名称:gosuv,代码行数:11,代码来源:fsm.go
示例18: handleReadDir
func handleReadDir(ctx context.Context, c *client.Client) error {
fInfos, err := c.ReadDir(ctx, readDirName)
if err != nil {
log.Fatalf("ReadDir err (%v)", err)
}
for _, stats := range fInfos {
fmt.Printf("%s: %d %t\n", stats.Name, stats.TotalSize, stats.IsDir == true)
}
return nil
}
开发者ID:missmayo,项目名称:cfs,代码行数:12,代码来源:readdir_command.go
示例19: NewConfigContext
func NewConfigContext() {
workDir, err := ExecDir()
if err != nil {
qlog.Fatalf("Fail to get work directory: %s\n", err)
}
cfgPath := filepath.Join(workDir, "conf/app.ini")
Cfg, err = goconfig.LoadConfigFile(cfgPath)
if err != nil {
qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err)
}
Cfg.BlockMode = false
cfgPaths := []string{os.Getenv("GOGS_CONFIG"), filepath.Join(workDir, "custom/conf/app.ini")}
for _, cfgPath := range cfgPaths {
if com.IsFile(cfgPath) {
if err = Cfg.AppendFiles(cfgPath); err != nil {
qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err)
}
}
}
AppName = Cfg.MustValue("", "APP_NAME", "Gogs: Go Git Service")
AppLogo = Cfg.MustValue("", "APP_LOGO", "img/favicon.png")
AppUrl = Cfg.MustValue("server", "ROOT_URL")
Domain = Cfg.MustValue("server", "DOMAIN")
OfflineMode = Cfg.MustBool("server", "OFFLINE_MODE", false)
DisableRouterLog = Cfg.MustBool("server", "DISABLE_ROUTER_LOG", false)
SecretKey = Cfg.MustValue("security", "SECRET_KEY")
InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false)
RunUser = Cfg.MustValue("", "RUN_USER")
curUser := os.Getenv("USER")
if len(curUser) == 0 {
curUser = os.Getenv("USERNAME")
}
// Does not check run user when the install lock is off.
if InstallLock && RunUser != curUser {
qlog.Fatalf("Expect user(%s) but current user is: %s\n", RunUser, curUser)
}
LogInRememberDays = Cfg.MustInt("security", "LOGIN_REMEMBER_DAYS")
CookieUserName = Cfg.MustValue("security", "COOKIE_USERNAME")
CookieRememberName = Cfg.MustValue("security", "COOKIE_REMEMBER_NAME")
PictureService = Cfg.MustValue("picture", "SERVICE")
DisableGravatar = Cfg.MustBool("picture", "DISABLE_GRAVATAR", false)
// Determine and create root git reposiroty path.
homeDir, err := com.HomeDir()
if err != nil {
qlog.Fatalf("Fail to get home directory): %v\n", err)
}
RepoRootPath = Cfg.MustValue("repository", "ROOT", filepath.Join(homeDir, "gogs-repositories"))
if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil {
qlog.Fatalf("Fail to create RepoRootPath(%s): %v\n", RepoRootPath, err)
}
ScriptType = Cfg.MustValue("repository", "SCRIPT_TYPE", "bash")
}
开发者ID:CubeLite,项目名称:gogs,代码行数:60,代码来源:conf.go
示例20: NewConfigContext
func NewConfigContext() {
//var err error
workDir, err := ExecDir()
if err != nil {
qlog.Fatalf("Fail to get work directory: %s\n", err)
}
cfgPath := filepath.Join(workDir, "conf/app.ini")
Cfg, err = goconfig.LoadConfigFile(cfgPath)
if err != nil {
qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err)
}
Cfg.BlockMode = false
cfgPath = filepath.Join(workDir, "custom/conf/app.ini")
if com.IsFile(cfgPath) {
if err = Cfg.AppendFiles(cfgPath); err != nil {
qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err)
}
}
AppName = Cfg.MustValue("", "APP_NAME", "Gogs: Go Git Service")
AppLogo = Cfg.MustValue("", "APP_LOGO", "img/favicon.png")
AppUrl = Cfg.MustValue("server", "ROOT_URL")
Domain = Cfg.MustValue("server", "DOMAIN")
SecretKey = Cfg.MustValue("security", "SECRET_KEY")
InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false)
RunUser = Cfg.MustValue("", "RUN_USER")
curUser := os.Getenv("USER")
if len(curUser) == 0 {
curUser = os.Getenv("USERNAME")
}
// Does not check run user when the install lock is off.
if InstallLock && RunUser != curUser {
qlog.Fatalf("Expect user(%s) but current user is: %s\n", RunUser, curUser)
}
LogInRememberDays = Cfg.MustInt("security", "LOGIN_REMEMBER_DAYS")
CookieUserName = Cfg.MustValue("security", "COOKIE_USERNAME")
CookieRememberName = Cfg.MustValue("security", "COOKIE_REMEMBER_NAME")
// load LDAP authentication configuration if present
LdapAuth = Cfg.MustBool("security", "LDAP_AUTH", false)
if LdapAuth {
log.Debug("LDAP AUTHENTICATION activated")
nbsrc := 0
for _, v := range Cfg.GetSectionList() {
if matched, _ := regexp.MatchString("(?i)^LDAPSOURCE.*", v); matched {
ldapname := Cfg.MustValue(v, "name", v)
ldaphost := Cfg.MustValue(v, "host")
ldapport := Cfg.MustInt(v, "port", 389)
ldapbasedn := Cfg.MustValue(v, "basedn", "dc=*,dc=*")
ldapattribute := Cfg.MustValue(v, "attribute", "mail")
ldapfilter := Cfg.MustValue(v, "filter", "(*)")
ldapmsadsaformat := Cfg.MustValue(v, "MSADSAFORMAT", "%s")
ldap.AddSource(ldapname, ldaphost, ldapport, ldapbasedn, ldapattribute, ldapfilter, ldapmsadsaformat)
nbsrc += 1
log.Debug("%s added as LDAP source", ldapname)
}
}
if nbsrc == 0 {
log.Debug("No valide LDAP found, LDAP AUTHENTICATION NOT activated")
LdapAuth = false
}
} else {
log.Debug("LDAP AUTHENTICATION NOT activated")
}
PictureService = Cfg.MustValue("picture", "SERVICE")
// Determine and create root git reposiroty path.
homeDir, err := com.HomeDir()
if err != nil {
qlog.Fatalf("Fail to get home directory): %v\n", err)
}
RepoRootPath = Cfg.MustValue("repository", "ROOT", filepath.Join(homeDir, "gogs-repositories"))
if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil {
qlog.Fatalf("Fail to create RepoRootPath(%s): %v\n", RepoRootPath, err)
}
ScriptType = Cfg.MustValue("repository", "SCRIPT_TYPE", "bash")
}
开发者ID:kennylixi,项目名称:gogs,代码行数:83,代码来源:conf.go
注:本文中的github.com/qiniu/log.Fatalf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论