代码之家  ›  专栏  ›  技术社区  ›  kentor

如果go模块损坏怎么办

go
  •  1
  • kentor  · 技术社区  · 6 年前

    mod init

    问题是:

    /Users/redacted/Documents/redacted3/redacted2>Finished running tool: /usr/local/bin/go vet ./...
    /Users/redacted/go/pkg/mod/github.com/sirupsen/logrus@v1.2.0/entry.go:51: undefined: Logger
    /Users/redacted/go/pkg/mod/github.com/sirupsen/logrus@v1.2.0/entry.go:54: undefined: Fields
    /Users/redacted/go/pkg/mod/github.com/sirupsen/logrus@v1.2.0/entry.go:61: undefined: Level
    

    我怎样才能摆脱这些恼人的依赖性问题呢?

    log "github.com/sirupsen/logrus"
    

    github.com/sirupsen/logrus v1.2.0
    
    2 回复  |  直到 6 年前
        1
  •  2
  •   kentor    6 年前

    我必须删除我的系统中的模块 /go/pkg/mod/github.com/... 解决问题的路径。Appparently在创建模块或最初从github提取代码时出错。

    go get

        2
  •  0
  •   NajlaBioinfo    6 年前
    • https://github.com/sirupsen/logrus . 下面的代码适用于我。

    • 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. :) ")
              }
      
    • module logrustest
      
      require github.com/sirupsen/logrus v1.2.0 // indirect
      
    • 输出: enter image description here

    祝你好运:)