本文整理匯總了Golang中github.com/golang/glog.Fatalln函數的典型用法代碼示例。如果您正苦於以下問題:Golang Fatalln函數的具體用法?Golang Fatalln怎麽用?Golang Fatalln使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Fatalln函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createSession
func createSession(w http.ResponseWriter, r *http.Request, session *sessions.Session) *ServerSession {
// Each session needs a unique ID in order to be saved.
if session.ID == "" {
session.ID = tokens.NewSessionID()
}
ss := &ServerSession{
CSRFToken: tokens.NewCSRFToken(session.ID),
}
// Attempt to store the session. Remove the session if it's not stored
// correctly.
if err := ss.StoreSession(session.ID); err != nil {
RemoveSession(session.ID)
glog.Fatalln(err)
}
// Similarly, save it in our FS storage and set the user's cookie.
if err := session.Save(r, w); err != nil {
RemoveSession(session.ID)
glog.Fatalln(err)
}
return ss
}
示例2: configFrom
func configFrom(file string) *config.Config {
// Find the file...
if file != "" {
if _, err := os.Stat(file); os.IsNotExist(err) {
glog.Fatalln("Cannot find specified configuration file", file, ", aborting.")
}
} else if _, err := os.Stat(os.Getenv("CAYLEY_CFG")); err == nil {
file = os.Getenv("CAYLEY_CFG")
} else if _, err := os.Stat("/etc/cayley.cfg"); err == nil {
file = "/etc/cayley.cfg"
}
if file == "" {
glog.Infoln("Couldn't find a config file in either $CAYLEY_CFG or /etc/cayley.cfg. Going by flag defaults only.")
}
cfg, err := config.Load(file)
if err != nil {
glog.Fatalln(err)
}
if cfg.DatabasePath == "" {
cfg.DatabasePath = *databasePath
}
if cfg.DatabaseType == "" {
cfg.DatabaseType = *databaseBackend
}
return cfg
}
示例3: Listen
func Listen(m *Manager, port string) {
addr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf(":%s", port))
if err != nil {
glog.Fatalln("HandleIncoming:", err)
}
l, err := net.ListenTCP("tcp", addr)
if err != nil {
glog.Fatalln("HandleIncoming:", err)
}
defer l.Close()
for {
conn, err := l.AcceptTCP()
if err != nil {
glog.Errorln("HandleIncoming:", err)
continue
}
host, port, err := net.SplitHostPort(conn.RemoteAddr().String())
if err != nil {
glog.Errorln("HandleIncoming:", err)
continue
}
glog.Infoln("Incoming Host: %s Port: %s", host, port)
m.AddPeer(host, port, false, conn)
}
}
示例4: init
func init() {
// Generate the reverse of our enum so we can work backwards and reload
// a file with the name instead of the enum.
//
// The issue arises because we've decided to use an array instead of a map
// to describe our in-memory templates. While this is more efficient, it
// causes issues with our hot reloading because the name of the file
// given to us from inotify is the string representation of the file's
// name, and we can't match that up with the enum on the fly (or generate
// code that does that using //go: generate). So, we run an init func that
// generates a map of the names to the enum so we can work backwards to
// reload the file.
for i := 0; i < len(_TmplName_index)-1; i++ {
key := _TmplName_name[_TmplName_index[i]:_TmplName_index[i+1]]
TmplMap[key] = TmplName(i)
}
// Set up our watcher for hot reloads of modified files.
watcher, err := inotify.NewWatcher()
if err != nil {
glog.Fatalln(err)
}
err = watcher.Watch(templatePath)
if err != nil {
glog.Fatalln(err)
}
Tmpls.Watcher = watcher
Tmpls.Watch()
cleanup.Register("reload", watcher.Close) // Close watcher.
}
示例5: RegisterTram
// RegisterTram functionality
// enables trams to be attached to specific routes.
func (t *Server) RegisterTram(in *RPCMessage, out *RPCMessage) error {
glog.Infoln("RegisterTram received: " + in.CsvData)
out.PrepReply(in)
tempSplit := strings.Split(in.CsvData, ",")
routeID, err := strconv.Atoi(tempSplit[len(tempSplit)-1])
if err != nil {
glog.Fatalln("Error splitting out tram route from RPCMessage data.")
}
stops, err := inDatabase(routeID)
if err != nil {
glog.Fatalln("Route doesn't exist")
}
var data Tram
data.FromString(in.CsvData)
err = t.addClient(&data, routeID)
if err != nil {
out.Status = 1
} else {
// pass current and previous stops to client
// these represent the starting (depo) location
out.CsvData = fmt.Sprintf("%d,%d", stops[0], stops[1])
}
return nil
}
示例6: main
func main() {
log.SetFlags(0)
flag.Set("logtostderr", "true")
flag.Parse()
if *url == "" {
fmt.Println("you need to set the parameter post-url")
os.Exit(1)
}
data, err := json.Marshal(machinedata.HostData{
Serial: fetchDMISerial(),
NetDevs: fetchNetDevs(),
ConnectedNIC: fetchConnectedNIC(),
IPMIAddress: fetchIPMIAddress(),
})
if err != nil {
glog.Fatalln(err)
}
resp, err := http.Post(*url, "application/json", bytes.NewBuffer(data))
if err != nil {
glog.Fatalln(err)
}
io.Copy(os.Stdout, resp.Body)
}
示例7: ParseConfig
// parse config file.
func ParseConfig(cfg string) {
if cfg == "" {
glog.Fatalln("use -c to specify configuration file")
}
if !file.IsExist(cfg) {
glog.Fatalln("config file:", cfg, "is not existent. maybe you need `mv cfg.example.json cfg.json`")
}
ConfigFile = cfg
configContent, err := file.ToTrimString(cfg)
if err != nil {
glog.Fatalln("read config file:", cfg, "fail:", err)
}
var c GlobalConfig
err = json.Unmarshal([]byte(configContent), &c)
if err != nil {
glog.Fatalln("parse config file:", cfg, "fail:", err)
}
configLock.Lock()
defer configLock.Unlock()
config = &c
glog.Infoln("g:ParseConfig, ok, ", cfg)
}
示例8: main
func main() {
httpAddr := flag.String("http", "127.0.0.1:5000", "address and port to listen on")
httpDocroot := flag.String("root", "www", "HTTP document root for static web files")
dataPath := flag.String("data", "/usr/local/var/lib/shadowcaster", "data directory (for indexes and such)")
flag.Parse()
Config = config{
IndexPath: *dataPath,
HTTPAddr: *httpAddr,
HTTPDocumentRoot: *httpDocroot}
// Run consistency checks on the indexes.
glog.Infoln("Running consistency checks on the indexes")
if err := CheckIndexes(*dataPath); err != nil {
glog.Fatalln(err)
}
glog.Infoln("Consistency checks passed")
// Set up the HTTP handling.
http.HandleFunc("/movies/", HandleMovies)
http.HandleFunc("/movies/setdir", HandleSetMovieDir)
http.HandleFunc("/movies/status", HandleMovieStatus)
http.HandleFunc("/tv/", HandleTV)
http.HandleFunc("/music/", HandleMusic)
http.HandleFunc("/pictures/", HandlePictures)
http.HandleFunc("/settings/", HandleSettings)
http.Handle("/", http.FileServer(http.Dir(*httpDocroot)))
glog.Infof("Listening on %v", *httpAddr)
if err := http.ListenAndServe(*httpAddr, nil); err != nil {
glog.Fatalln(err)
}
glog.Infof("ShadowCaster offline")
}
示例9: setup
func setup() {
flag.Parse()
numCPU := runtime.NumCPU()
glog.Infoln("NumCPU", numCPU)
if envMaxProcs := os.Getenv("GOMAXPROCS"); envMaxProcs == "" {
if numCPU > 1 {
// Consuming N-1 appears to greatly reduce per-request latency in loaded systems.
runtime.GOMAXPROCS(numCPU - 1)
}
}
glog.Infoln("GOMAXPROCS", runtime.GOMAXPROCS(0))
var d db.DB
switch *useDB {
case "cassandra":
d = cassandradb.New()
default:
glog.Fatalln("Unknown DB:", *useDB)
}
if err := d.Init(); err != nil {
glog.Fatalln("An error occured Initializing the DB: ", err)
}
handlers.InitializeAndRegister(d)
}
示例10: MonitorFeeds
func MonitorFeeds(reg *registry.Registry) {
if reg.Feeds == "" {
return
}
f, err := os.Open(reg.Feeds)
if err != nil {
glog.Fatalln("Reading feeds:", err)
}
defer f.Close()
var feeds []Feed
if err := json.NewDecoder(f).Decode(&feeds); err != nil {
glog.Fatalln("Decoding feeds:", err)
}
db := reg.DB()
defer db.Session.Close()
for i := range feeds {
if err := db.C("feeds").FindId(feeds[i].DocType).One(&feeds[i]); err != nil && err != mgo.ErrNotFound {
glog.Fatalln("Finding existing feeds:", err)
}
feeds[i].stream, err = eventsource.Subscribe(feeds[i].Url, feeds[i].LastEventId)
if err == nil {
glog.Infof("Monitoring: %s", &feeds[i])
go monitor(reg, &feeds[i])
} else {
glog.Fatalln("Eventsource:", err)
}
}
}
示例11: WriteIgnitionConfig
func (mgr *pxeManagerT) WriteIgnitionConfig(host hostmgr.Host, wr io.Writer) error {
etcdClusterToken := mgr.cluster.Config.DefaultEtcdClusterToken
if host.EtcdClusterToken != "" {
etcdClusterToken = host.EtcdClusterToken
}
mergedTemplatesEnv := mgr.config.TemplatesEnv
for k, v := range host.Overrides {
mergedTemplatesEnv[k] = v
}
ctx := struct {
Host hostmgr.Host
EtcdDiscoveryUrl string
ClusterNetwork network
MayuHost string
MayuPort int
MayuURL string
PostBootURL string
NoTLS bool
TemplatesEnv map[string]interface{}
}{
Host: host,
ClusterNetwork: mgr.config.Network,
EtcdDiscoveryUrl: fmt.Sprintf("%s/%s", mgr.etcdDiscoveryUrl, etcdClusterToken),
MayuHost: mgr.config.Network.BindAddr,
MayuPort: mgr.httpPort,
MayuURL: mgr.thisHost(),
PostBootURL: mgr.thisHost() + "/admin/host/" + host.Serial + "/boot_complete",
NoTLS: mgr.noTLS,
TemplatesEnv: mergedTemplatesEnv,
}
ctx.Host.MayuVersion = mgr.version
tmpl, err := getTemplate(mgr.ignitionConfig, mgr.templateSnippets)
if err != nil {
glog.Fatalln(err)
return err
}
var data bytes.Buffer
if err = tmpl.Execute(&data, ctx); err != nil {
glog.Fatalln(err)
return err
}
ignitionJSON, e := convertTemplatetoJSON(data.Bytes(), false)
if e != nil {
glog.Fatalln(e)
return e
}
fmt.Fprintln(wr, string(ignitionJSON[:]))
return nil
}
示例12: init
func init() {
glog.SetToStderr(true)
cfg, err := configFrom("cayley_appengine.cfg")
if err != nil {
glog.Fatalln("Error loading config:", err)
}
handle, err := db.Open(cfg)
if err != nil {
glog.Fatalln("Error opening database:", err)
}
http.SetupRoutes(handle, cfg)
}
示例13: zoneproxy
func zoneproxy(v *viper.Viper, dp *dialer.DialerPool) {
var wg sync.WaitGroup
zones := v.GetStringMap("zones")
dp.AddByZones(zones)
tcpproxys := v.GetStringMap("tcpproxys")
for name, _ := range tcpproxys {
address := v.GetString("tcpproxys." + name + ".address")
if address == "" {
glog.Fatalln("tcpproxys." + name + ".address must be string")
}
tp := tcpproxy.NewTcpProxy(name, address, dp, v)
wg.Add(1)
go func() {
tp.Run()
wg.Done()
}()
}
httpproxys := v.GetStringMap("httpproxys")
for name, _ := range httpproxys {
address := v.GetString("httpproxys." + name + ".address")
if address == "" {
glog.Fatalln("httpproxys." + name + ".address must be string")
}
hp := httpproxy.NewHttpProxy(name, address, dp, v)
wg.Add(1)
go func() {
hp.Run()
wg.Done()
}()
}
httpservers := v.GetStringMap("httpservers")
for name, _ := range httpservers {
address := v.GetString("httpservers." + name + ".address")
if address == "" {
glog.Fatalln("httpservers." + name + ".address must be string")
}
hs := httpserver.NewHttpServer(name, address, dp, v)
wg.Add(1)
go func() {
hs.Run()
wg.Done()
}()
}
wg.Wait()
glog.Flush()
}
示例14: workerSentry
func workerSentry(engine cfg.Engine, index int) chan os.Signal {
workersigchan := make(chan os.Signal, 1) //channel for signal delivery to worker processes
engineType := engine.Name
signalForStop := false
go func() {
defer func() {
glog.Infoln("workerSentry out", engineType, index)
wg.Done()
}()
for {
glog.Infoln("workerSentry start", engineType, index, *workerExe)
cmd := exec.Command(*workerExe,
"-cfg", cfg.ConfigFile,
"-engine-cfg", cfg.EngineConfigFile,
"-i", fmt.Sprint(index),
"-engine", engineType)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Start()
starttime := time.Now()
if err != nil {
glog.Fatalln(err)
return
}
glog.Infoln("Waiting for command to finish", engineType, index)
c := make(chan string)
go func() {
cmd.Wait()
glog.Infoln("Finished wait", engineType, index)
close(c)
}()
outer:
for {
select {
case res := <-c:
//wait for container to finish
glog.Infoln("finished worker execution", res, engineType, index)
if signalForStop {
return
} else {
if time.Since(starttime) < 30*time.Second {
glog.Infoln("finished before sleep", engineType, index)
glog.Flush()
time.Sleep(30 * time.Second)
glog.Infoln("finished sleep", engineType, index)
}
break outer
}
case sig := <-workersigchan:
glog.Infoln("workersigchan signal ", engineType, index, sig)
signalForStop = true
cmd.Process.Signal(sig)
}
}
}
}()
return workersigchan
}
示例15: SaveSyncMessage
func (storage *Storage) SaveSyncMessage(emsg *EMessage) error {
storage.mutex.Lock()
defer storage.mutex.Unlock()
filesize, err := storage.file.Seek(0, os.SEEK_END)
if err != nil {
log.Fatalln(err)
}
if emsg.msgid != filesize {
log.Warningf("file size:%d, msgid:%d is't equal", filesize, emsg.msgid)
if emsg.msgid < filesize {
log.Warning("skip msg:", emsg.msgid)
} else {
log.Warning("write padding:", emsg.msgid-filesize)
padding := make([]byte, emsg.msgid-filesize)
_, err = storage.file.Write(padding)
if err != nil {
log.Fatal("file write:", err)
}
}
}
storage.WriteMessage(storage.file, emsg.msg)
storage.ExecMessage(emsg.msg, emsg.msgid)
log.Info("save sync message:", emsg.msgid)
return nil
}