INT 21h

Hi, I am Vladimir Smagin, SysAdmin and Kaptain. Telegram Email / GIT / RSS / GPG

Golang: set variable during build

№ 11467 В разделе Programming от December 12th, 2021,
В подшивках:

Useful to set version or build number. Also you can use embed.


package main

import "fmt"

var MyVariable = "jopa"

func main() {
	fmt.Printf("%s\n", MyVariable)

Build script:


ENVVAR="jopa i piska"

  "-X 'main.MyVariable=${ENVVAR}'"

go build -o testvar -ldflags="${LDFLAGS[*]}" main.go

rm -f ./testvar


$ ./ 
jopa i piska

Нет комментариев »

Leave a Reply

Your email address will not be published. Required fields are marked *


Облачная платформа

Fortune cookie: Handel's Proverb: You can't produce a baby in one month by impregnating 9 women!