本文整理汇总了Golang中log.Exitf函数的典型用法代码示例。如果您正苦于以下问题:Golang Exitf函数的具体用法?Golang Exitf怎么用?Golang Exitf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Exitf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
runtime.LockOSThread()
if srpc.Enabled() {
go srpc.ServeRuntime()
}
w, err := av.Init(av.SubsystemVideo, 512, 512)
if err != nil {
log.Exitf("av.Init: %s", err)
}
go quitter(w.QuitChan())
var m SpacewarPDP1
m.Init(w)
m.PC = 4
f := bytes.NewBuffer(strings.Bytes(spacewarCode))
if err = m.Load(f); err != nil {
log.Exitf("loading %s: %s", "spacewar.lst", err)
}
for err == nil {
//fmt.Printf("step PC=%06o ", m.PC);
//fmt.Printf("inst=%06o AC=%06o IO=%06o OV=%o\n",
// m.Mem[m.PC], m.AC, m.IO, m.OV);
err = m.Step()
}
log.Exitf("step: %s", err)
}
示例2: main
func main() {
flag.Parse()
if sumSet(flagFile, flagBlob, flagPermanode, flagInit, flagShare) != 1 {
// TODO: say which ones are conflicting
usage("Conflicting mode options.")
}
client := client.NewOrFail()
if !*flagVerbose {
client.SetLogger(nil)
}
uploader := &Uploader{client}
switch {
case *flagInit:
doInit()
return
case *flagPermanode:
if flag.NArg() > 0 {
log.Exitf("--permanode doesn't take any additional arguments")
}
pr, err := uploader.UploadNewPermanode()
handleResult("permanode", pr, err)
case *flagFile || *flagBlob:
for n := 0; n < flag.NArg(); n++ {
if *flagBlob {
pr, err := uploader.UploadFileBlob(flag.Arg(n))
handleResult("blob", pr, err)
} else {
pr, err := uploader.UploadFile(flag.Arg(n))
handleResult("file", pr, err)
}
}
case *flagShare:
if flag.NArg() != 1 {
log.Exitf("--share only supports one blobref")
}
br := blobref.Parse(flag.Arg(0))
if br == nil {
log.Exitf("BlobRef is invalid: %q", flag.Arg(0))
}
pr, err := uploader.UploadShare(br, *flagTransitive)
handleResult("share", pr, err)
}
if *flagVerbose {
stats := uploader.Stats()
log.Printf("Client stats: %s", stats.String())
}
if wereErrors {
os.Exit(2)
}
}
示例3: main
func main() {
flag.Parse()
urandom, err := os.Open("/dev/urandom", os.O_RDONLY, 0)
if err != nil {
log.Exitf("failed to open /dev/urandom: %s", err)
return
}
priv, err := rsa.GenerateKey(urandom, 1024)
if err != nil {
log.Exitf("failed to generate private key: %s", err)
return
}
now := time.Seconds()
template := x509.Certificate{
SerialNumber: []byte{0},
Subject: x509.Name{
CommonName: *hostName,
Organization: "Acme Co",
},
NotBefore: time.SecondsToUTC(now - 300),
NotAfter: time.SecondsToUTC(now + 60*60*24*365), // valid for 1 year.
SubjectKeyId: []byte{1, 2, 3, 4},
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
}
derBytes, err := x509.CreateCertificate(urandom, &template, &template, &priv.PublicKey, priv)
if err != nil {
log.Exitf("Failed to create certificate: %s", err)
return
}
certOut, err := os.Open("cert.pem", os.O_WRONLY|os.O_CREAT, 0644)
if err != nil {
log.Exitf("failed to open cert.pem for writing: %s", err)
return
}
pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
certOut.Close()
log.Print("written cert.pem\n")
keyOut, err := os.Open("key.pem", os.O_WRONLY|os.O_CREAT, 0600)
if err != nil {
log.Print("failed to open key.pem for writing:", err)
return
}
pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)})
keyOut.Close()
log.Print("written key.pem\n")
}
示例4: StaticUrl
func StaticUrl(filename string) string {
file, err := os.Open(GetConfig("docroot") + "/" + filename, os.O_RDONLY, 0444)
if err != nil {
log.Exitf("Impossible to open %s", filename, err)
}
dir, err := file.Stat()
if err != nil {
log.Exitf("Impossible to stat %s", filename, err)
}
secs := dir.Mtime_ns / 1e9
return fmt.Sprintf("/%s?%d", filename, secs)
}
示例5: readTemplate
func readTemplate(name string) *template.Template {
fileName := path.Join(*root, "tmpl", name)
data, err := ioutil.ReadFile(fileName)
if err != nil {
log.Exitf("ReadFile %s: %v", fileName, err)
}
t, err := template.Parse(string(data), fmap)
if err != nil {
log.Exitf("%s: %v", fileName, err)
}
return t
}
示例6: readTemplate
func readTemplate(name string) *template.Template {
path := pathutil.Join(*tmplroot, name)
data, err := ioutil.ReadFile(path)
if err != nil {
log.Exitf("ReadFile %s: %v", path, err)
}
t, err := template.Parse(string(data), fmap)
if err != nil {
log.Exitf("%s: %v", name, err)
}
return t
}
示例7: WriteConfig
func WriteConfig(config *Config) {
buf := &bytes.Buffer{}
err := json.Marshal(buf, *config)
if err != nil {
log.Exitf("Failed to marshal config file: %s\n", err)
}
// TODO atomic update without truncating file
err = io.WriteFile(configFilename, buf.Bytes(), configPerms)
if err != nil {
log.Exitf("Can't write config file: %s\n", err)
}
}
示例8: main
func main() {
flag.Parse()
client := client.NewOrFail()
if *flagCheck {
// Simply do HEAD requests checking if the blobs exists.
return
}
var w io.Writer = os.Stdout
for n := 0; n < flag.NArg(); n++ {
arg := flag.Arg(n)
br := blobref.Parse(arg)
if br == nil {
log.Exitf("Failed to parse argument \"%s\" as a blobref.", arg)
}
if *flagVerbose {
log.Printf("Need to fetch %s", br.String())
}
var (
r blobref.ReadSeekCloser
err os.Error
)
if len(*flagVia) > 0 {
vs := strings.Split(*flagVia, ",", -1)
abr := make([]*blobref.BlobRef, len(vs))
for i, sbr := range vs {
abr[i] = blobref.Parse(sbr)
if abr[i] == nil {
log.Exitf("Invalid -via blobref: %q", sbr)
}
if *flagVerbose {
log.Printf("via: %s", sbr)
}
}
r, _, err = client.FetchVia(br, abr)
} else {
r, _, err = client.Fetch(br)
}
if err != nil {
log.Exitf("Failed to fetch %q: %s", br, err)
}
_, err = io.Copy(w, r)
if err != nil {
log.Exitf("Failed transferring %q: %s", br, err)
}
}
}
示例9: ReadConfig
func ReadConfig(filename string) {
contents, err := ioutil.ReadFile(filename)
if err != nil {
log.Exitf("Impossible to read %s", filename, err)
}
data, err := json.Decode(string(contents))
if err != nil {
log.Exitf("Can't parse %s as JSON", filename, err)
}
config = map[string]string{}
for key, value := range data.(map[string]interface{}) {
config[key] = value.(string)
}
}
示例10: main
func main() {
nlmsg, err := netlink.NewMessage(rtnetlink.RTM_GETADDR, netlink.NLM_F_DUMP|netlink.NLM_F_REQUEST, &addr.Header{}, 4)
if err != nil {
log.Exitf("Couldn't construct message: %v", err)
}
log.Printf("Dialing: %v", nlmsg)
nlsock, err := netlink.Dial(netlink.NETLINK_ROUTE)
if err != nil {
log.Exitf("Couldn't dial netlink: %v", err)
}
h := netlink.NewHandler(nlsock)
ec := make(chan os.Error)
go logec(ec)
go h.Start(ec)
log.Printf("Sending query: %v", nlmsg)
c, err := h.Query(*nlmsg, 1, 4)
log.Printf("Sent query: %v", nlmsg.Header)
if err != nil {
log.Exitf("Couldn't write netlink: %v", err)
}
for i := range c {
if i.Header.MessageType() == netlink.NLMSG_DONE {
break
}
switch i.Header.MessageType() {
case rtnetlink.RTM_NEWADDR:
hdr := &addr.Header{}
msg := rtnetlink.NewMessage(hdr, nil)
err = msg.UnmarshalNetlink(i.Body, 4)
if err == nil {
log.Printf("Family: %v; Length: %d; Flags: %v; Scope: %v; IFIndex: %d",
hdr.AddressFamily(), hdr.PrefixLength(), hdr.Flags(), hdr.Scope(),
hdr.InterfaceIndex())
for i := range msg.Attributes {
log.Printf("Attribute[%d] = %v", i, msg.Attributes[i])
}
} else {
log.Printf("Unmarshal error: %v", err)
}
default:
log.Printf("Unknown type: %v", i)
}
if err != nil {
log.Printf("Handler error: %v", err)
}
}
}
示例11: main
func main() {
var address, key string
var count, delay, step int
flag.StringVar(&address, "address", "127.0.0.1:6311", "Set the port (+optional address) to send packets to")
flag.StringVar(&key, "key", "profile", "Set the key name (pakets data will be \"key:idx\")")
flag.IntVar(&count, "count", 1000, "Set the number of packets to send")
flag.IntVar(&delay, "delay", 1000000, "Set the delay between packets in nanoseconds (10^-9)")
flag.IntVar(&step, "step", 100, "Log step (how many packets to send between logging)")
flag.Parse()
udp_address, error := net.ResolveUDPAddr(address)
if error != nil {
log.Exitf("Cannot parse \"%s\": %s", address, error)
}
log.Stdout(udp_address)
ticker := time.NewTicker(int64(delay))
defer ticker.Stop()
for sent := 1; sent <= count; sent++ {
<-ticker.C
send(udp_address, key, sent)
if sent%step == 0 {
log.Stdoutf("Processed %d packets of %d", sent, count)
}
}
}
示例12: CallWithProgress
func (c *client) CallWithProgress(method string, data []byte, progress ProgressHandler) []byte {
// TODO: implement
// TODO: shard onto a c.hosts[] entry, wait for its connection state, etc.
log.Exitf("TODO: implement CallWithProgress")
return nil
}
示例13: ReadConfig
func ReadConfig() *Config {
content, err := io.ReadFile(configFilename)
if err != nil {
log.Exitf("Can't open config file: %s\n", err)
}
return ParseConfig(string(content))
}
示例14: main
func main() {
flag.Parse()
readTemplates()
if *root == "" {
var err os.Error
*root, err = os.Getwd()
if err != nil {
log.Exitf("Failed to getwd: %v", err)
}
}
mux := http.DefaultServeMux
mux.Handle("/favicon.ico", http.FileServer(path.Join(*root, "static"), "/"))
mux.Handle("/robots.txt", http.FileServer(path.Join(*root, "static"), "/"))
mux.Handle("/static/", http.FileServer(path.Join(*root, "static"), "/static/"))
testCgi := &CgiHandler{ExecutablePath: path.Join(*root, "test.cgi"),
Root: "/test.cgi",
}
mux.Handle("/test.cgi", testCgi)
mux.Handle("/test.cgi/foo", testCgi)
mux.Handle("/code", http.RedirectHandler("/code/", http.StatusFound))
if *gitwebScript != "" {
env := os.Environ()
env = append(env, "GITWEB_CONFIG="+path.Join(*root, "gitweb-camli.conf"))
env = append(env, "CAMWEB_ROOT="+path.Join(*root))
mux.Handle("/code/", &gitwebHandler{
Cgi: &CgiHandler{
ExecutablePath: *gitwebScript,
Root: "/code/",
Environ: env,
},
Static: http.FileServer(*gitwebFiles, "/code/"),
})
}
mux.HandleFunc("/", mainHandler)
var handler http.Handler = &noWwwHandler{Handler: mux}
if *logDir != "" || *logStdout {
handler = NewLoggingHandler(handler, *logDir, *logStdout)
}
if err := http.ListenAndServe(*httpAddr, handler); err != nil {
log.Exitf("ListenAndServe %s: %v", *httpAddr, err)
}
}
示例15: ParseConfig
func ParseConfig(config string) *Config {
var c = &Config{}
ok, errtok := json.Unmarshal(config, c)
if !ok {
log.Exitf("Config syntax error: %s\n", errtok)
}
return c
}