本文整理匯總了Golang中github.com/golang/glog.Flush函數的典型用法代碼示例。如果您正苦於以下問題:Golang Flush函數的具體用法?Golang Flush怎麽用?Golang Flush使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Flush函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewReporter
func (ereporter *EtcdReporter) NewReporter(sc *configuration.ServiceConf) error {
config := client.Config{
Endpoints: sc.ReporterHosts,
Transport: client.DefaultTransport,
}
c, err := client.New(config)
if err != nil {
glog.Errorf("SRegister: create etcd client failed. Error: %v", err)
glog.Flush()
return err
} else {
ereporter.etcdClient = client.NewKeysAPI(c)
}
ereporter.path = "/"
if sc.ReporterPath != "" {
ereporter.path = sc.ReporterPath
}
str, derr := getServiceData(sc)
if derr != nil {
glog.Errorf("SRegister: geenrate service value failed. Error: %v", derr)
glog.Flush()
return derr
}
ereporter.value = str
ereporter.key = ""
return nil
}
示例2: send
func send(tcpconn *net.TCPConn, rsp *Response) (err error) {
Len := uint32(PkgLenSize) + uint32(len(rsp.Head)) + uint32(len(rsp.Body))
Hlen := uint16(Uint16Size) + uint16(len(rsp.Head))
data := make([]byte, 0, int(Len)) // len:0, cap:Len; TODO(zog): cache
buf := bytes.NewBuffer(data) // TODO(zog): 複用
binary.Write(buf, binary.BigEndian, Len)
binary.Write(buf, binary.BigEndian, Hlen)
buf.Write(rsp.Head)
buf.Write(rsp.Body)
if debug {
glog.Infof("sent bytes to %s, len: %d",
tcpconn.RemoteAddr().String(), len(buf.Bytes()))
glog.Flush()
}
tcpconn.SetDeadline(time.Now().Add(100 * time.Millisecond))
if _, err = tcpconn.Write(buf.Bytes()); err != nil {
return err
}
if debug {
glog.Infof("sent data(len:%d): %v", buf.Len(), buf.Bytes())
glog.Flush()
}
return nil
}
示例3: makeHandler
//調用相應的處理函數前進行預處理
func makeHandler(fn func(http.ResponseWriter, *http.Request, string)) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
//防止程序panic,this is a safe handle.
defer func() {
if e, ok := recover().(error); ok {
http.Error(w, "internal error.", http.StatusInternalServerError)
glog.Errorf("WARN: panic in %v. - %v", fn, e)
}
}()
//end
//記錄訪問日誌
glog.V(0).Infof("%s\t%s\t%s\t%s\t%s\t%s", r.Method, r.RemoteAddr, r.URL.Path, r.Proto, r.Referer(), r.UserAgent())
//目前隻接受get請求,其餘請求忽略
switch r.Method {
case "GET":
m := validPath.FindStringSubmatch(r.URL.Path)
if m == nil {
http.NotFound(w, r)
return
}
fn(w, r, r.URL.Path)
glog.Flush()
return
default:
http.Error(w, "method not support...", http.StatusInternalServerError)
glog.Flush()
return
}
}
}
示例4: main
func main() {
defer glog.Flush()
glog.CopyStandardLogTo("info")
flag.Parse()
runtime.GOMAXPROCS(runtime.NumCPU())
httpClientBuilder := http_client_builder.New().WithoutProxy()
httpClient := httpClientBuilder.Build()
requestbuilderProvider := http_requestbuilder.NewHTTPRequestBuilderProvider()
downloader := debian_url_downloader.New(httpClient.Do, requestbuilderProvider.NewHTTPRequestBuilder)
lineInspector := debian_line_inspector.New(downloader.DownloadURL)
hasChanged := debian_apt_source_has_changed.New(lineInspector.HasLineChanged)
bool, err := do(
hasChanged,
*pathPtr,
)
if err != nil {
glog.Exit(err)
}
if bool {
glog.Flush()
os.Exit(0)
} else {
glog.Flush()
os.Exit(1)
}
}
示例5: main
func main() {
flag.Parse() // SetupDB()
dbConn, err := mssql.NewConn(*mssrv, *msdb, *msuser, *mspass)
if dbConn == nil || err != nil {
log.Fatal(err)
}
if log.V(2) {
log.Infof("DOP %d", *dop)
log.Flush()
}
migTables(dbConn, *dop)
log.Flush()
}
示例6: main
func main() {
flag.Parse()
timeout, err := time.ParseDuration(*timeoutDuration)
if err != nil {
glog.Fatalf("proxy: failed to parse timeout duration: %s", err)
}
proxy, err := mixnet.NewProxyContext(*configPath, *network, *proxyAddr, timeout)
if err != nil {
glog.Fatalf("failed to configure proxy: %s", err)
}
defer proxy.Close()
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
go func() {
sig := <-sigs
proxy.Close()
glog.Infof("router: closing on signal: %s", sig)
signo := int(sig.(syscall.Signal))
os.Exit(0x80 + signo)
}()
if err = serveClients(*routerAddr, proxy); err != nil {
glog.Errorf("proxy: error while serving: %s", err)
}
glog.Flush()
}
示例7: Test_List
// test mesos.List
func Test_List(t *testing.T) {
defer log.Flush()
md := FakeMasterDetector{}
httpServer, httpClient, httpTransport := makeHttpMocks()
defer httpServer.Close()
cacheTTL := 500 * time.Millisecond
mesosClient, err := createMesosClient(md, httpClient, httpTransport, cacheTTL)
mesosCloud := &MesosCloud{client: mesosClient, config: createDefaultConfig()}
clusters, err := mesosCloud.List(".*") // recognizes the language of all strings
if err != nil {
t.Fatalf("List does not yield an error: %#v", err)
}
if len(clusters) != 3 {
t.Fatalf("List with a catch-all filter should return a list of size 3: (actual: %#v)", clusters)
}
clusters, err = mesosCloud.List("$^") // end-of-string followed by start-of-string: recognizes the empty language
if err != nil {
t.Fatalf("List does not yield an error: %#v", err)
}
if len(clusters) != 0 {
t.Fatalf("List with a reject-all filter should return a list of size 0: (actual: %#v)", clusters)
}
}
示例8: main
func main() {
var (
config *Config
zk *Zookeeper
p *Pitchfork
err error
)
flag.Parse()
defer log.Flush()
log.Infof("bfs pitchfork start")
if config, err = NewConfig(configFile); err != nil {
log.Errorf("NewConfig(\"%s\") error(%v)", configFile, err)
return
}
log.Infof("init zookeeper...")
if zk, err = NewZookeeper(config.ZookeeperAddrs, config.ZookeeperTimeout, config.ZookeeperPitchforkRoot, config.ZookeeperStoreRoot,
config.ZookeeperVolumeRoot); err != nil {
log.Errorf("NewZookeeper() failed, Quit now")
return
}
log.Infof("register pitchfork...")
if p, err = NewPitchfork(zk, config); err != nil {
log.Errorf("pitchfork NewPitchfork() failed, Quit now")
return
}
log.Infof("starts probe stores...")
go p.Probe()
StartSignal()
return
}
示例9: main
func main() {
glog.Info("Web Server:Loading...")
b := flag.Bool("benchmark", false, "")
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
if *b {
glog.Info("Benchmark Mode")
// Creat a file
f, err := os.Create("pprof")
if err != nil {
glog.Fatal(err)
}
if err = pprof.StartCPUProfile(f); err != nil {
glog.Fatal(err)
}
defer pprof.StopCPUProfile()
}
defer glog.Flush()
glog.Info("Read the config.")
if err := InitConf(); err != nil {
glog.Fatal(err)
}
glog.Info("[Web]: listener start.")
go start()
signal.HandleSignal(signal.InitSignal())
}
示例10: main
func main() {
defer glog.Flush()
glog.CopyStandardLogTo("info")
flag.Parse()
runtime.GOMAXPROCS(runtime.NumCPU())
httpClientBuilder := http_client_builder.New()
httpClient := httpClientBuilder.Build()
latestInformations := atlassian_utils_latest_information.New(bitbucket.JSON_URL, httpClient.Get)
latestUrl := atlassian_utils_latest_tar_gz_url.New(latestInformations.VersionInformations)
latestVersion := atlassian_utils_latest_version.New(latestInformations.VersionInformations)
commandListProvider := func() command_list.CommandList {
return command_list.New()
}
config_parser := debian_config_parser.New()
copier := debian_copier.New()
zipExtractor := debian_zip_extractor.New()
tarGzExtractor := debian_tar_gz_extractor.New()
requestbuilderProvider := http_requestbuilder.NewHTTPRequestBuilderProvider()
debianPackageCreator := debian_package_creator.New(commandListProvider, copier, tarGzExtractor.ExtractTarGz, zipExtractor.ExtractZip, httpClient.Do, requestbuilderProvider.NewHTTPRequestBuilder)
creatorByReader := debian_package_creator_by_reader.New(commandListProvider, debianPackageCreator, tarGzExtractor.ExtractTarGz)
latestDebianPackageCreator := debian_latest_package_creator.New(httpClient.Get, latestUrl.LatestConfluenceTarGzUrl, latestVersion.LatestVersion, creatorByReader.CreatePackage)
err := do(
latestDebianPackageCreator.CreateLatestDebianPackage,
config_parser,
*configPtr,
latestVersion.LatestVersion,
*targetDirPtr,
)
if err != nil {
glog.Exit(err)
}
}
示例11: main
func main() {
defer glog.Flush()
flag.Parse()
if *inputFile == "" {
glog.Fatal("--input flag cannot be empty")
}
b, err := ioutil.ReadFile(*inputFile)
if err != nil {
glog.Fatal(err)
}
var userAgents []*userAgent
err = json.Unmarshal(b, &userAgents)
if err != nil {
glog.Fatal(err)
}
var all, success int
for _, client := range userAgents {
all++
if testClient(client) {
success++
}
}
glog.Infof("done %d/%d %.2f%%", success, all, (float64(success)/float64(all))*100.0)
}
示例12: setupLogging
func setupLogging(duration time.Duration) {
go func() {
for _ = range time.Tick(duration) {
glog.Flush()
}
}()
}
示例13: main
func main() {
flag.Parse()
defer glog.Flush()
reg := descriptor.NewRegistry()
glog.V(1).Info("Processing code generator request")
f := os.Stdin
if *file != "stdin" {
f, _ = os.Open("input.txt")
}
req, err := parseReq(f)
if err != nil {
glog.Fatal(err)
}
if req.Parameter != nil {
for _, p := range strings.Split(req.GetParameter(), ",") {
spec := strings.SplitN(p, "=", 2)
if len(spec) == 1 {
if err := flag.CommandLine.Set(spec[0], ""); err != nil {
glog.Fatalf("Cannot set flag %s", p)
}
continue
}
name, value := spec[0], spec[1]
if strings.HasPrefix(name, "M") {
reg.AddPkgMap(name[1:], value)
continue
}
if err := flag.CommandLine.Set(name, value); err != nil {
glog.Fatalf("Cannot set flag %s", p)
}
}
}
g := genswagger.New(reg)
reg.SetPrefix(*importPrefix)
if err := reg.Load(req); err != nil {
emitError(err)
return
}
var targets []*descriptor.File
for _, target := range req.FileToGenerate {
f, err := reg.LookupFile(target)
if err != nil {
glog.Fatal(err)
}
targets = append(targets, f)
}
out, err := g.Generate(targets)
glog.V(1).Info("Processed code generator request")
if err != nil {
emitError(err)
return
}
emitFiles(out)
}
示例14: pushImage
// pushImage pushes a docker image to the registry specified in its tag.
// The method will retry to push the image when following scenarios occur:
// - Docker registry is down temporarily or permanently
// - other image is being pushed to the registry
// If any other scenario the push will fail, without retries.
func pushImage(client DockerClient, name string, authConfig docker.AuthConfiguration) error {
repository, tag := docker.ParseRepositoryTag(name)
opts := docker.PushImageOptions{
Name: repository,
Tag: tag,
}
if glog.V(5) {
opts.OutputStream = os.Stderr
}
var err error
for retries := 0; retries <= DefaultPushRetryCount; retries++ {
err = client.PushImage(opts, authConfig)
if err == nil {
return nil
}
errMsg := fmt.Sprintf("%s", err)
if !strings.Contains(errMsg, "ping attempt failed with error") && !strings.Contains(errMsg, "is already in progress") {
return err
}
util.HandleError(fmt.Errorf("push for image %s failed, will retry in %s seconds ...", name, DefaultPushRetryDelay))
glog.Flush()
time.Sleep(DefaultPushRetryDelay)
}
return err
}
示例15: main
func main() {
defer glog.Flush()
glog.CopyStandardLogTo("info")
flag.Parse()
runtime.GOMAXPROCS(runtime.NumCPU())
httpClient := http_client_builder.New().WithoutProxy().Build()
requestbuilder_executor := aptly_requestbuilder_executor.New(httpClient.Do)
requestbuilder := http_requestbuilder.NewHTTPRequestBuilderProvider()
repo_publisher := aptly_repo_publisher.New(requestbuilder_executor, requestbuilder)
repo_creater := aptly_repo_creater.New(requestbuilder_executor, requestbuilder, repo_publisher.PublishNewRepo)
if len(*repoURLPtr) == 0 {
*repoURLPtr = *apiURLPtr
}
err := do(
repo_creater,
*repoURLPtr,
*apiURLPtr,
*apiUserPtr,
*apiPasswordPtr,
*apiPasswordFilePtr,
*repoPtr,
*distributionPtr,
strings.Split(*architecturePtr, ","),
)
if err != nil {
glog.Exit(err)
}
}