Is it possible to run Go code as a script?

后端 未结 5 2058
梦如初夏
梦如初夏 2021-02-05 17:21

As Go is becoming the language of the \"system\". I wonder if it\'s possible to run Go code as a script, without compiling it, is there any possibility to do that?

The

5条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-05 17:48

    I am not an expert in go, but you can do something like this. I know this is not elegant, but may be something to start with :)

    ~$ cat vikas.go
    //usr/bin/env go run "$0" "$@"; exit
    
    package main
    
    import "fmt"
    
    func main() {
        fmt.Printf("Hello World\n")
    }
    ~$
    
    ~$ ./vikas.go
    Hello World
    ~$
    

提交回复
热议问题