Go Compiler


Compile-Time Variables

Consider the below sample program, hello:

package main

import (
        "fmt"
)

var Name string

func main() {
        fmt.Printf("Hello, %s!\n", Name)
}

$ go build && ./hello 
Hello, !
$ go build -ldflags "-X main.Name=Dominic" && ./hello 
Hello, Dominic!


CategoryRicottone

Go/Compiler (last edited 2021-11-04 18:08:07 by DominicRicottone)