亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如果 go 模塊壞了怎么辦

如果 go 模塊壞了怎么辦

Go
汪汪一只貓 2023-05-08 16:25:25
作為 Node.js 開發人員,我對 Golang 還是個新手,并且在 Go 中的依賴管理方面苦苦掙扎。我正在使用 Go 1.11 并mod init在導入所有依賴項后應用。其中之一是 logrus,它阻止我編譯我的 go 應用程序。問題:我相信問題確實在 logrus 內部,但是我不知道我現在如何獲得另一個(工作)版本的 logrus,以便我可以再次編譯我的應用程序。/Users/redacted/Documents/redacted3/redacted2>Finished running tool: /usr/local/bin/go vet ./.../Users/redacted/go/pkg/mod/github.com/sirupsen/[email protected]/entry.go:51: undefined: Logger/Users/redacted/go/pkg/mod/github.com/sirupsen/[email protected]/entry.go:54: undefined: Fields/Users/redacted/go/pkg/mod/github.com/sirupsen/[email protected]/entry.go:61: undefined: Level我怎樣才能擺脫這些煩人的依賴問題?相關進口:log "github.com/sirupsen/logrus"Go.mod 包含github.com/sirupsen/logrus v1.2.0
查看完整描述

2 回答

?
Cats萌萌

TA貢獻1805條經驗 獲得超9個贊

我不得不刪除/go/pkg/mod/github.com/...解決問題的路徑中的模塊。顯然在創建模塊或最初從 github 中提取代碼時出了點問題。

之后我go get再次使用我的 logrus lib,它按預期工作。


查看完整回答
反對 回復 2023-05-08
?
嗶嗶one

TA貢獻1854條經驗 獲得超8個贊

  • 我認為 logrus 模塊很好,您只是缺少“log.WithFields”定義。

  • main.go 文件:

//Source : https://github.com/sirupsen/logrus

//logrus version : require github.com/sirupsen/logrus v.1.2.0

//go version go1.11.2 linux/amd64



package main


import (

//Go package

"os"

"fmt"

log "github.com/sirupsen/logrus"

)


//Checking if the logout file exist

//Just to show the Fatal tag.

func Exists(name string) bool {

? ? ? ? _, err := os.Stat(name)

? ? ? ? return !os.IsNotExist(err)

}



func main() {

? ? ? ? fmt.Println("I'am the main here ... all begin ...")?


? ? ? ? log.WithFields(log.Fields{"main": "main process",}).Info("Initialization.")

? ? ? ? log.WithFields(log.Fields{"main": "...some codes....",}).Warn("Nothting here yet.")


? ? ? ? log.WithFields(log.Fields{"main":"main process",}).Info("It's done. Thanks.")


? ? ? ? //The check here (it's just for demo) so you can see the others tags

? ? ? ? if Exists("paht/to/mylogoutfile") == false {

? ? ? ? ? ? ? ? log.WithFields(log.Fields{"main": "Checking logoutputfile path.",}).Fatal("Mising the Logout file.")

}


? ? ? ? //fmt.Println("This is the end Thankyou for using this. :) ")

? ? ? ? }

go.mod 文件:


module logrustest


require github.com/sirupsen/logrus v1.2.0 // indirect

輸出 :

http://img1.sycdn.imooc.com/6458b21b0001c5d106260083.jpg

查看完整回答
反對 回復 2023-05-08
  • 2 回答
  • 0 關注
  • 167 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號