Skip to content

获取当前工作目录并保存到一个包级别的变量中 #22

Open
@AlexZ33

Description

@AlexZ33

可以通过os.Getwd完成
但是当我们需要处理错误时,将这个从主逻辑中分离出来会更好。函数log.Fatalf用于打印日志信息然后调用os.Exit()来终止程序。

var cwd string

func init(){
    var err error
    cwd, err = os.Getwd()
    if err != nil{
        log.Fatalf("os.Getwd failed: %v", err)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions