本文整理汇总了Golang中github.com/thomasf/lg.Warningln函数的典型用法代码示例。如果您正苦于以下问题:Golang Warningln函数的具体用法?Golang Warningln怎么用?Golang Warningln使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Warningln函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: generateRandomBytes
// generateRandomBytes returns securely generated random bytes. It will return
// an error if the system's secure random number generator fails to function
// correctly, in which case the caller should not continue.
func generateRandomBytes(n int) []byte {
b := make([]byte, n)
_, err := rand.Read(b)
if err != nil {
lg.Warningln("could not generate secure random key, using non secure random instead")
lg.Warningln(err)
for i := 0; i < n; i++ {
b[i] = byte(mrand.Intn(256))
}
}
return b
}
示例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: ErrToAPIStatus
// errToAPIStatus converts an error to an api.Status object.
func ErrToAPIStatus(err error) *api.Status {
switch t := err.(type) {
case statusError:
status := t.Status()
if len(status.Status) == 0 {
status.Status = api.StatusFailure
}
if status.Code == 0 {
switch status.Status {
case api.StatusSuccess:
status.Code = http.StatusOK
case api.StatusFailure:
status.Code = http.StatusInternalServerError
}
}
//TODO: check for invalid responses
return &status
default:
status := http.StatusInternalServerError
// Log errors that were not converted to an error status
// by REST storage - these typically indicate programmer
// error by not using pkg/api/errors, or unexpected failure
// cases.
lg.Warningln(fmt.Errorf("apiserver received an error that is not an api.Status: %v", err))
return &api.Status{
Status: api.StatusFailure,
Code: status,
Reason: api.StatusReasonUnknown,
Message: err.Error(),
}
}
}
示例4: New
func (s *singleUseAuthKeyStore) New() string {
b := make([]byte, 10)
_, err := rand.Read(b)
if err != nil {
lg.Warningln("could not generate secure random key, using non secure random instead")
lg.Warningln(err)
for i := 0; i < len(b); i++ {
b[i] = byte(mrand.Intn(256))
}
}
key := hex.EncodeToString(b)
s.Lock()
defer s.Unlock()
s.entries[key] = time.Now()
return key
}
示例5: SetLastProcessedSampleID
func (d *DB) SetLastProcessedSampleID(id uint64) error {
psql := squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar)
idstr := strconv.FormatUint(id, 10)
s := psql.
Update("central_state").
Set("value", idstr).
Where(squirrel.Eq{"name": "last_processed_sample_id"})
sr, err := s.RunWith(d.cache).Exec()
if err != nil {
logSQLErr(err, &s)
log.Fatal(err)
}
sn, err := sr.RowsAffected()
if err != nil {
lg.Warningln(err)
return err
}
if sn > 0 {
return nil
}
i := psql.
Insert("central_state").
Columns("name", "value").
Values("last_processed_sample_id", idstr)
ir, err := i.RunWith(d.cache).Exec()
if err != nil {
logSQLErr(err, &i)
log.Fatal(err)
}
in, err := ir.RowsAffected()
if err != nil {
lg.Warningln(err)
return err
}
if in > 0 {
return nil
}
log.Fatal("unknown error")
return nil
}
示例6: Wait
// Wait blocks until the underlying process is stopped
func (s *Service) Wait() {
if s.cmd != nil {
lg.V(10).Infof("Waiting for process %s to exit", s.ID)
err := s.cmd.Wait()
if err != nil {
lg.Warningln(err)
}
lg.V(10).Infof("%s exited", s.ID)
}
s.waiter.Wait()
}
示例7: AtexitKillCmd
// AtexitKillCmd takes care of killing a command on application exit.
//
// TODO: currently this does not clean up references to dead processes, it just
// adds forever.
func AtexitKillCmd(cmd *exec.Cmd) {
Atexit(func() {
lg.V(10).Info("Atexit kill ", cmd.Path, cmd.Args)
err := cmd.Process.Kill()
if err != nil {
lg.V(5).Info("kill failed:", err)
}
// TODO: possible deadlock?
if err := cmd.Wait(); err != nil {
lg.Warningln(err)
}
})
}
示例8: 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
}
}
}
}
示例9: 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
}
示例10: wait
// Wait blocks until the underlying process is stopped
func (s *Service) wait() {
if s.isCopy {
lg.Fatal("wait called on copy of service!")
}
if s.cmd != nil {
lg.V(10).Infof("Waiting for process %s to exit", s.ID)
err := s.cmd.Wait()
if err != nil {
lg.Warningln(err)
}
lg.V(10).Infof("%s exited", s.ID)
}
s.waiter.Wait()
}
示例11: connect
func connect(connection shared.Connection, authKey string) {
defaultTransportM.RLock()
if defaultTransport != nil {
err := defaultTransport.Remove()
if err != nil {
lg.Warningln(err)
}
}
defaultTransportM.RUnlock()
event := newConnectionEventhistory(connection)
event.newState(ServiceInit)
ts, err := NewTransportService(connection)
ts.authSecret = authKey
if lg.V(6) {
ts.SetVerbose()
}
ts.SetBindaddr(DefaultProxyBindAddr)
if err != nil {
event.newState(Failed)
event.newState(Ended)
return
}
event.newState(ServiceStart)
event.ServiceID = ts.Service.ID
err = ts.Start()
if err != nil {
event.newState(Failed)
event.newState(Ended)
return
}
response := ts.Service.Response
if response["protocol"] != "socks5" {
event.newState(WrongProtocol)
event.newState(Failed)
}
event.newState(Test)
go testConn(&event)
defaultTransportM.Lock()
defaultTransport = ts
defaultTransportM.Unlock()
}
示例12: NewDebugResposne
// NewDebugResponse creates a filled DebugResponse struct
func NewDebugResposne(version string, config interface{}) *DebugResponse {
ID, err := shared.SecureRandomString(12)
if err != nil {
panic("could not generate random number")
}
response := &DebugResponse{
Header: DebugHeader{
Cmd: filepath.Base(os.Args[0]),
ID: ID,
Version: version,
CreatedAt: time.Now(),
OS: runtime.GOOS,
Arch: runtime.GOARCH,
GoVersion: runtime.Version(),
},
Config: config,
}
getProfile := func(name string) []string {
buf := bytes.NewBuffer(nil)
err := pprof.Lookup(name).WriteTo(buf, 2)
if err != nil {
lg.Errorln(err)
} else {
return strings.Split(
buf.String(),
"\n")
}
return []string{}
}
response.Heap = getProfile("heap")
response.GoRoutines = getProfile("goroutine")
response.ThreadCreate = getProfile("threadcreate")
response.Block = getProfile("block")
// memlog should be last so that it can catch errors up to the point of
// collection.
response.Log = lg.Memlog()
if PublicKey != "" {
response.Encrypt(PublicKey)
} else {
lg.Warningln("PublicKey not set, exporting unencrypted debug log")
}
return response
}
示例13: GetSuggestions
// GetSuggestions returns all local/remote suggestion sessions, can be filtered
// by time of creation.
func GetSuggestions(w rest.ResponseWriter, r *rest.Request) {
var res []client.Suggestion
all := client.AllSuggestions()
after := r.URL.Query().Get("after")
if after == "" {
res = all
} else {
after, err := time.Parse(time.RFC3339, after)
if err != nil {
lg.Warningln("Wrong time format: %s", after)
return
}
for _, v := range all {
if v.CreatedAt.After(after) {
res = append(res, v)
}
}
}
w.WriteJson(res)
}
示例14: StartBinaryUpgradeChecker
// StartBinaryUpgradeChecker checks for binary upgrades when the connection is
// up and on a schedule.
//
// This function runs in it's own goroutine.
func StartBinaryUpgradeChecker(diffsBaseURL string) {
if !upgradeEnabled {
lg.Infoln("binary upgrades are disabled using the command line flag")
return
}
if VERSION == "" {
lg.Warningln("VERSION not set, binary upgrades are disabled")
return
}
_, err := version.NewVersion(VERSION)
if err != nil {
lg.Warningf("VERSION '%s' is not a valid semver version, binary upgrades are disabled: %v", VERSION, err)
return
}
connectionEventListener := make(chan service.ConnectionHistory)
uChecker, _ := NewUpdateChecker("binary")
service.AddListener(connectionEventListener)
for {
select {
// Update when the transport connection comes up
case event := <-connectionEventListener:
if event.IsUp() {
uChecker.Activate()
uChecker.UpdateNow()
}
// Update by request of the update checker
case request := <-uChecker.RequestC:
err := upgradeBinaryCheck(diffsBaseURL)
if err != nil {
lg.Errorln(err)
request.ResponseC <- UpdateError
} else {
request.ResponseC <- UpdateSuccess
}
}
}
}
示例15: StartConnectionManager
func StartConnectionManager(authKey string) {
go updateTransportOkLoop()
listeners := make([]chan ConnectionHistory, 0)
// TODO: Test on irregular intervals
reverifyTicker := time.NewTicker(connectionManagerTimings.TestTransportTicker)
// the key is Connection.UUID
histories := make(map[string][]ConnectionEvent)
currents := make(map[string]*ConnectionEvent)
currentConnectionID := ""
currentConnectionsMu.Lock()
currentConnIdx := 0
if len(currents) < 1 {
go connect(currentConnections[currentConnIdx], authKey)
currentConnectionID = currentConnections[currentConnIdx].ID
}
currentConnectionsMu.Unlock()
firstUpNoProblems := true // no need to spam the user with popups
var reconnectTimer *time.Timer
var connectionTestRunning bool
loop:
for {
s:
select {
case <-stopCh:
lg.Infoln("connection manager shut down")
break loop
case <-reconnectCh:
currentConnectionsMu.Lock()
if len(currentConnections) < 1 {
currentConnectionsMu.Unlock()
lg.Warningln("No connections enabled")
reconnectTimer = time.AfterFunc(connectionManagerTimings.ReconnectTransportDelay, func() {
reconnectCh <- true
})
break s
}
currentConnIdx = (currentConnIdx + 1) % (len(currentConnections))
c := currentConnections[currentConnIdx]
lg.V(10).Infof("reconnecting to transport %v", c)
go connect(currentConnections[currentConnIdx], authKey)
currentConnectionID = c.ID
currentConnectionsMu.Unlock()
case listener := <-addNetworkStateListener:
listeners = append(listeners, listener)
case event := <-connectionEvents:
if _, v := histories[event.Connection.ID]; !v {
histories[event.Connection.ID] = make([]ConnectionEvent, 0)
} else if len(histories[event.Connection.ID]) > 20 {
lg.V(5).Infoln("trimming connection history")
histories[event.Connection.ID] = histories[event.Connection.ID][:20]
}
histories[event.Connection.ID] = append(histories[event.Connection.ID], event)
currents[event.Connection.ID] = &event
emitEvent := ConnectionHistory{
History: histories[event.Connection.ID],
}
if lg.V(3) {
switch event.State {
case Failed, TestFailed:
lg.Warningln("event ", event.Connection.ID, ": ", event.State)
default:
lg.Infoln("event ", event.Connection.ID, ": ", event.State)
}
}
switch event.State {
case Up:
if firstUpNoProblems {
firstUpNoProblems = false
} else {
ui.Notify("transport_connected_message")
}
case Failed:
firstUpNoProblems = false
ui.Notify("transport_error_message")
case TestFailed:
firstUpNoProblems = false
ui.Notify("transport_retry")
case Ended:
delete(currents, event.Connection.ID)
lg.V(15).Infoln("waiting before sending reconnect")
if reconnectTimer != nil {
reconnectTimer.Stop()
}
reconnectTimer = time.AfterFunc(connectionManagerTimings.ReconnectTransportDelay, func() {
reconnectCh <- true
})
}
lg.V(7).Infoln("Forwarding connection event to listeners", emitEvent.Current())
for _, l := range listeners {
//.........这里部分代码省略.........