本文整理匯總了Golang中github.com/inconshreveable/log15.Logger.New方法的典型用法代碼示例。如果您正苦於以下問題:Golang Logger.New方法的具體用法?Golang Logger.New怎麽用?Golang Logger.New使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/inconshreveable/log15.Logger
的用法示例。
在下文中一共展示了Logger.New方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: WebsocketHandler
func WebsocketHandler(srv *context.T, log log15.Logger) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
log := log.New("cmp", "websocket")
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Error("error upgrading websocket connetion", "err", err)
return
}
ch := srv.Router.Sub("/block")
defer srv.Router.Unsub(ch)
loop:
select {
case blki := <-ch:
if blk, ok := blki.(*block.Block); ok {
encoded, err := json.Marshal(blk)
if err != nil {
log.Error("error encoding block", "err", err)
return
}
if err = conn.WriteMessage(websocket.TextMessage, encoded); err != nil {
log.Error("error sending data", "err", err)
return
}
}
}
goto loop
}
}
示例2: InfoHandler
func InfoHandler(srv *context.T, log log15.Logger) func(http.ResponseWriter, *http.Request) {
return func(resp http.ResponseWriter, req *http.Request) {
log := log.New("http")
lastBlock, err := srv.DB.GetLastBlock()
if err != nil {
log.Error("error serving /info", "err", err)
}
info := Info{
Mining: server.GetMiningStatus(),
LastBlock: lastBlock,
}
info.Debug.NumGoroutine = runtime.NumGoroutine()
json, err := json.Marshal(info)
if err != nil {
log.Error("error serving /info", "err", err)
}
resp.Header().Add("Content-Type", "application/json")
resp.Write(json)
}
}
示例3: SetupGitRoutes
func SetupGitRoutes(r *mux.Router, srv *context.T, log log15.Logger) {
log = log.New("cmp", "git")
// Git Server
r.Methods("POST").Path("/{repository:.+}/git-upload-pack").HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
log := log.New("cmp", "git-upload-pack")
dec := pktline.NewDecoder(req.Body)
resp.Header().Add("Cache-Control", "no-cache")
resp.Header().Add("Content-Type", "application/x-git-upload-pack-result")
enc := pktline.NewEncoder(resp)
var wants, haves, common []git.Hash
var objects []git.Object
wantsRcvd := false
for {
var pktline []byte
if err := dec.Decode(&pktline); err != nil {
log.Error("error while decoding pkt-line", "err", err)
return
}
switch {
case pktline == nil:
switch {
case !wantsRcvd:
wantsRcvd = true
case wantsRcvd:
for i := range haves {
_, err := readObject(srv, haves[i])
if err == nil {
enc.Encode([]byte(fmt.Sprintf("ACK %x common\n", haves[i])))
common = append(common, haves[i])
} else {
enc.Encode([]byte("NAK\n"))
}
}
haves = make([]git.Hash, 0)
}
case bytes.Compare(pktline, []byte("done\n")) == 0:
if len(common) == 0 {
enc.Encode([]byte("NAK\n"))
}
goto done
default:
line := bytes.Split(pktline, []byte{' '})
h := bytes.TrimSuffix(line[1], []byte{10})
hash, err := hex.DecodeString(string(h))
if err != nil {
enc.Encode(append([]byte{3}, []byte(fmt.Sprintf("error parsing hash %s: %v\n", line[1], err))...))
return
}
if string(line[0]) == "want" {
wants = append(wants, hash)
}
if string(line[0]) == "have" {
haves = append(haves, hash)
}
}
}
done:
var err error
for i := range wants {
var objs []git.Object
objs, err = processCommit(srv, wants[i], common)
if err != nil {
enc.Encode(append([]byte{3}, []byte(fmt.Sprintf("%s", err))...))
return
}
objects = append(objects, objs...)
}
// filter out duplicates
seen := make(map[string]bool)
filteredObjects := make([]git.Object, 0)
for i := range objects {
hash := string(objects[i].Hash())
if !seen[hash] {
seen[hash] = true
filteredObjects = append(filteredObjects, objects[i])
}
}
//
packfile := git.NewPackfile(filteredObjects)
err = git.WritePackfile(&sideband64Writer{writer: &pktlineWriter{encoder: enc}, band: 1}, packfile)
if err != nil {
enc.Encode(append([]byte{3}, []byte(fmt.Sprintf("%s", err))...))
return
}
enc.Encode(append([]byte{1}, pktlineToBytes(nil)...))
enc.Encode(nil)
})
r.Methods("POST").Path("/{repository:.+}/git-receive-pack").HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
reponame := mux.Vars(req)["repository"]
var lines [][]byte
dec := pktline.NewDecoder(req.Body)
dec.DecodeUntilFlush(&lines)
resp.Header().Add("Cache-Control", "no-cache")
resp.Header().Add("Content-Type", "application/x-git-receive-pack-result")
//.........這裏部分代碼省略.........