本文整理汇总了Golang中github.com/thomasf/lg.Infof函数的典型用法代码示例。如果您正苦于以下问题:Golang Infof函数的具体用法?Golang Infof怎么用?Golang Infof使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Infof函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: scoreStatusCode
func scoreStatusCode(client, central int) float64 {
if central < 400 && client > 400 {
lg.Infof("status ranges %d != %d", client, central)
return 1.0
} else if client != central {
lg.Infof("status %d != %d", client, central)
return 0.7
} else if client != central {
return 0.0
}
return 0.5
}
示例2: startAnalysis
func startAnalysis(clients db.Clients) {
go func() {
tick := time.NewTicker(10 * time.Second)
lastID, err := clients.DB.GetLastProcessedSampleID()
if err != nil {
lg.Warningln(err)
}
lg.Infof("starting analysis from sample ID %d", lastID)
lastPersistedID := lastID
for range tick.C {
results, err := clients.DB.GetSamples(uint64(lastID), "")
if err != nil {
lg.Fatal(err)
}
n := 0
start := time.Now()
loop:
for s := range results {
n++
if s.ID > lastID {
lastID = s.ID
}
if s.Type == "NewClientToken" {
if !shared.AcceptedHost(s.Host) {
lg.Warningln("not accepted host id:", s.ID, s.Host)
continue loop
}
err := clients.DB.PublishHost(s)
if err != nil {
lg.Warning(err)
}
}
}
if n != 0 && lg.V(15) {
lg.Infof("processed %d samples in %s", n, time.Since(start).String())
}
if lastID != lastPersistedID {
err = clients.DB.SetLastProcessedSampleID(lastID)
if err != nil {
lg.Errorln(err)
} else {
lastPersistedID = lastID
}
}
}
}()
}
示例3: StartAnalysis
func StartAnalysis(clients db.Clients) {
tick := time.NewTicker(5 * time.Second)
lastID, err := clients.DB.GetLastProcessedSampleID()
if err != nil {
lg.Warningln(err)
}
for n := 0; n < 4; n++ {
go sessionFetcher(clients)
go samplesAnalyzer()
go hostPublisher(clients)
}
lg.Infof("starting analysis from sample ID %d", lastID)
lastPersistedID := lastID
for range tick.C {
results, err := clients.DB.GetSamples(uint64(lastID), "")
if err != nil {
lg.Errorf("database err (skipping): %v", err)
continue
}
n := 0
start := time.Now()
for s := range results {
n++
if s.ID > lastID {
lastID = s.ID
}
if s.Origin == "Central" && s.Type == "HTTPHeader" {
sessionFetchC <- s.Token
}
}
if n != 0 && lg.V(15) {
lg.Infof("processed %d samples in %s", n, time.Since(start).String())
}
if lastID != lastPersistedID {
err = clients.DB.SetLastProcessedSampleID(lastID)
if err != nil {
lg.Errorln(err)
} else {
lastPersistedID = lastID
}
}
}
}
示例4: getVersion
func (b *BuildQuery) getVersion() (*Artifact, error) {
lg.Infof("Getting versions of %s", b.ArtifactDisplayName())
c, err := getNexusClient()
if err != nil {
return nil, err
}
artifacts, err := c.Artifacts(
search.InRepository{
RepositoryID: repoID,
Criteria: search.ByCoordinates{
GroupID: "com.alkasir",
Version: b.Version,
ArtifactID: b.Cmd,
Classifier: b.Classifier(),
},
},
)
if err != nil {
return nil, err
}
if len(artifacts) != 1 {
lg.Infoln(artifacts)
return nil, errors.New("one match expected")
}
return &Artifact{Artifact: artifacts[0]}, nil
}
示例5: PostTransportTraffic
func PostTransportTraffic(w rest.ResponseWriter, r *rest.Request) {
form := shared.TransportTraffic{}
err := r.DecodeJsonPayload(&form)
if err != nil {
apiutils.WriteRestError(w, apierrors.NewInternalError(err))
return
}
transportTrafficMu.Lock()
defer transportTrafficMu.Unlock()
transportTraffic = form
if lg.V(10) {
if len(transportTrafficLog) == 6 {
lg.Infof("transport traffic: %.0fkb/s %.0fkb/s %.0fkb/s %.0fkb/s %.0fkb/s %.0fkb/s",
(transportTrafficLog[0].Throughput)/1024,
(transportTrafficLog[1].Throughput)/1024,
(transportTrafficLog[2].Throughput)/1024,
(transportTrafficLog[3].Throughput)/1024,
(transportTrafficLog[4].Throughput)/1024,
(transportTrafficLog[5].Throughput)/1024,
)
transportTrafficLog = make([]shared.TransportTraffic, 0)
}
if transportTraffic.Throughput > 1024 {
transportTrafficLog = append(transportTrafficLog, form)
}
}
response := true
w.WriteJson(response)
}
示例6: testConn
func testConn(event *ConnectionEvent) error {
defaultTransportM.RLock()
defer defaultTransportM.RUnlock()
if defaultTransport == nil {
transportOkC <- false
event.newState(TestFailed)
event.newState(NotConfigured)
event.newState(Ended)
return errors.New("No active transport")
}
err := testSocks5Internet(defaultTransport.Service.Response["bindaddr"])
if err != nil {
transportOkC <- false
event.newState(TestFailed)
event.newState(Failed)
event.newState(Ended)
return errors.New("Http get test failed")
} else {
if event.State != Up && lg.V(4) {
lg.Infof("event: tested %s -> %s (%s)", event.State, Up, event.ServiceID)
}
transportOkC <- true
if event.State != Up {
event.newState(Up)
}
}
transportOkC <- true
return nil
}
示例7: GetVersions
func (b *BuildQuery) GetVersions() (Artifacts, error) {
lg.Infof("Getting versions of %s", b.ArtifactDisplayName())
c, err := getNexusClient()
if err != nil {
return nil, err
}
artifacts, err := c.Artifacts(
search.InRepository{
RepositoryID: repoID,
Criteria: search.ByCoordinates{
GroupID: "com.alkasir",
ArtifactID: b.Cmd,
Classifier: b.Classifier(),
},
},
)
if err != nil {
return nil, err
}
var result Artifacts
for _, na := range artifacts {
a, err := newArtifact(na)
if err != nil {
return nil, err
}
result = append(result, a)
}
sort.Sort(result)
return result, nil
}
示例8: Download
// Download downloads the artifact to a local directory
func (a *Artifact) Download() error {
shortURL := a.Info().URL
shortURL = shortURL[strings.LastIndex(shortURL, "/")+1:]
lg.Infof("Downloading %s", shortURL)
err := os.MkdirAll(a.Dir("dl"), 0775)
if err != nil {
return err
}
err = download(a.Path(), a.Info().URL)
if err != nil {
lg.Warningf("Error downloading %s", shortURL)
} else {
lg.Infof("Downloaded %s", shortURL)
}
return err
}
示例9: WriteToDisk
func (d *DebugResponse) WriteToDisk() error {
dir := d.filename()
if err := os.MkdirAll(dir, 0775); err != nil {
panic(err)
}
writeTextFile := func(data []string, basename string) error {
filename := filepath.Join(dir, basename+".txt")
f, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, 0665)
if err != nil {
return err
}
defer f.Close()
for _, v := range data {
_, err := f.WriteString(v + "\n")
if err != nil {
return err
}
}
return nil
}
writeJsonFile := func(data interface{}, basename string) error {
bytes, err := json.MarshalIndent(&data, "", " ")
if err != nil {
panic(err)
}
filename := filepath.Join(dir, basename+".json")
err = ioutil.WriteFile(filename, bytes, 0665)
if err != nil {
return err
}
return nil
}
failed := false
for _, v := range []error{
writeJsonFile(d.Header, "header"),
writeTextFile(d.Log, "log"),
writeTextFile(d.Heap, "heap"),
writeTextFile(d.GoRoutines, "goroutines"),
writeTextFile(d.Block, "block"),
writeTextFile(d.ThreadCreate, "threadcreate"),
writeJsonFile(d.Config, "config"),
} {
if v != nil {
failed = true
lg.Error(v)
}
}
if failed {
return fmt.Errorf("errors writing out report %s", dir)
}
lg.Infof("wrote report for %s", dir)
return nil
}
示例10: main
func main() {
var bindaddr = flag.String("bindaddr", "0.0.0.0:7245", "bind address")
rand.Seed(time.Now().UnixNano())
flag.Parse()
flagenv.Prefix = "ALKASIR_WANIP_SERVER_"
flagenv.Parse()
lg.CopyStandardLogTo("INFO")
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
ipAddress, _, _ := net.SplitHostPort(r.RemoteAddr)
fmt.Fprintf(w, "%s", ipAddress)
if lg.V(5) {
lg.Infof("returning %s", ipAddress)
}
})
lg.Infof("Listening to http://%s", *bindaddr)
err := http.ListenAndServe(*bindaddr, nil)
if err != nil {
lg.Fatal(err)
}
}
示例11: testPatch
func testPatch(pr CreatePatchResult, publicKey string) error {
lg.Infof("verifying %s %s>%s", pr.Artifact, pr.OldVersion, pr.NewVersion)
tmpfile := fmt.Sprintf("/tmp/%s-%s-o", pr.Artifact, pr.OldVersion)
err := cp(tmpfile, pr.job.OldBinary)
if err != nil {
lg.Fatal(err)
}
defer func() {
err = os.Remove(tmpfile)
if err != nil {
lg.Errorln(err)
}
}()
sum, err := base64.RawURLEncoding.DecodeString(pr.SHA256Sum)
if err != nil {
return err
}
sig, err := upgradebin.DecodeSignature(pr.ED25519Signature)
if err != nil {
return err
}
pub, err := upgradebin.DecodePublicKey([]byte(publicKey))
if err != nil {
return err
}
opts := update.Options{
Patcher: update.NewBSDiffPatcher(),
Verifier: upgradebin.NewED25519Verifier(),
Hash: crypto.SHA256,
Checksum: sum,
Signature: sig[:],
PublicKey: pub,
TargetPath: tmpfile,
}
diffFile, err := os.Open(pr.DiffFile)
if err != nil {
return err
}
defer diffFile.Close()
err = update.Apply(diffFile, opts)
if err != nil {
return err
}
return nil
}
示例12: readSettings
func readSettings(c *Config) error {
lg.V(5).Info("Reading settings file")
isRead := false
_, err := mkConfigDir()
if err != nil {
return err
}
data, err := ioutil.ReadFile(ConfigPath("settings.json"))
if err != nil {
lg.Infof("Error loading settings.json %s", err)
} else {
settings, err := parseConfig(data)
if err != nil {
lg.Warningf("Config file error, deleting and resetting")
err := os.Remove(ConfigPath("settings.json"))
if err != nil {
lg.Warningf("Could not delete old settingsfile (should probably panic here)")
}
} else {
currentConfig.Settings = *settings
isRead = true
}
}
if !isRead {
settings, err := parseConfig([]byte(settingsTemplate))
if err != nil {
panic("invalid defaultsettings")
}
currentConfig.Settings = *settings
}
transports := make(map[string]shared.Transport, 0)
if currentConfig.Settings.Transports != nil {
for _, v := range currentConfig.Settings.Transports {
transports[v.Name] = v
}
}
for _, v := range []shared.Transport{
{Name: "obfs3", Bundled: true, TorPT: true},
{Name: "obfs4", Bundled: true, TorPT: true},
{Name: "shadowsocks-client", Bundled: true},
} {
transports[v.Name] = v
}
currentConfig.Settings.Transports = transports
return nil
}
示例13: HtmlHandler
// HtmlHandler is a HandlerFunc that serves all pages in the internal browser
// using a single html template.
func HtmlHandler(w http.ResponseWriter, r *http.Request) {
templates := loadTemplates()
err := templates.ExecuteTemplate(w, "page.html", struct {
Title string
PageData interface{}
}{
Title: "Alkasir",
},
)
if err != nil {
lg.Infof("err: %+v", err)
}
}
示例14: parseConfig
// SetConfig reads configuration from json byte stream
func parseConfig(config []byte) (*Settings, error) {
s := &Settings{}
err := json.Unmarshal(config, &s)
if err != nil {
return nil, err
}
for i, c := range s.Connections {
err := c.EnsureID()
if err != nil {
lg.Fatal(err)
}
lg.V(15).Infof("connection id: %s", c.ID)
if lg.V(50) {
v, _ := c.Encode()
lg.Infof("connection encoded: %s", v)
lg.Infof("connection full: %+v", c)
}
s.Connections[i] = c
}
return s, nil
}
示例15: NewUpdateChecker
// NewUpdateChecker creates and returns an UpdateChecker instance.
// The caller should then listen on the RequestC channel for UpdateRequests.
func NewUpdateChecker(name string) (*UpdateChecker, error) {
c := &UpdateChecker{
Interval: time.Duration(1*time.Hour + (time.Minute * (time.Duration(rand.Intn(120))))),
}
c.response = make(chan UpdateResult)
c.RequestC = make(chan UpdateRequest)
c.forceRequestC = make(chan bool)
lg.Infof("Setting up update timer for %s every %f minute(s) ",
name, c.Interval.Minutes())
ticker := time.NewTicker(c.Interval)
go func() {
for {
select {
case <-c.forceRequestC:
if !c.active {
continue
}
c.RequestC <- UpdateRequest{
ResponseC: c.response,
}
case <-ticker.C:
if !c.active {
continue
}
c.RequestC <- UpdateRequest{
ResponseC: c.response,
}
case response := <-c.response:
c.LastCheck = time.Now()
switch response {
case UpdateSuccess:
lg.V(5).Infoln("UpdateSuccess")
c.LastUpdate = c.LastCheck
c.LastFailedCheck = time.Time{}
case UpdateError:
lg.Warningln("update check failed")
c.LastFailedCheck = c.LastCheck
<-time.After(3*time.Second + time.Duration(rand.Intn(5)))
go func() {
c.forceRequestC <- true
}()
}
}
}
}()
return c, nil
}