FAQ
I am adding versioning info to may main app:
====================================
================
// MyApp.go
================
package main
import (
"geo"
"fmt"
"os"
)
var VERSION string
var MinVersion string

func main() {
RunName := os.Args[0]
fmt.Printf("\nRunName=%s VERSION=%s%s--------------------\n", RunName,
VERSION, MinVersion)
}
================


================
Build
================
go build -ldflags "-X main.VERSION 'v.1' -X main.MinVersion `date -u
+.%Y:%m:%d.%H:%M:%S`" MyApp.go
================

Run
================
./MyApp
================

RunName=./MyApp VERSION=v.1.2013:10:26.20:48:37--------------------

====================================

*This is working fine.*

Now I want to add versioning info to a package:
~/mygo/src/geo
====================================
package geo
var VERSION string
var MinVersion string

func GetVERSION() string {
return fmt.Sprintf("%s:%s%s", "geo", VERSION, MinVersion)
}
====================================
================
Install package
================
go install -ldflags "-X geo.VERSION 'v.1' -X geo.MinVersion `date -u
+.%Y:%m:%d.%H:%M:%S`"
================

================
// MyApp.go
================
package main
import (
"geo"
"fmt"
"os"
)

func main() {
fmt.Printf("\n%s\n", geo.GetVERSION())
}

================
Build
================
go build MyApp.go
================

Run
================
./MyApp
================

*geo.GetVERSION() is returning empty string.*

What I am missing?

--Constantine

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Minux at Oct 27, 2013 at 3:27 am

    On Sat, Oct 26, 2013 at 4:58 PM, Constantine Vass wrote:
    I am adding versioning info to may main app:
    ====================================
    ================
    // MyApp.go
    ================
    package main
    import (
    "geo"
    "fmt"
    "os"
    )
    var VERSION string
    var MinVersion string

    func main() {
    RunName := os.Args[0]
    fmt.Printf("\nRunName=%s VERSION=%s%s--------------------\n", RunName,
    VERSION, MinVersion)
    }
    ================


    ================
    Build
    ================
    go build -ldflags "-X main.VERSION 'v.1' -X main.MinVersion `date -u
    +.%Y:%m:%d.%H:%M:%S`" MyApp.go
    ================

    Run
    ================
    ./MyApp
    ================

    RunName=./MyApp VERSION=v.1.2013:10:26.20:48:37--------------------

    ====================================

    *This is working fine.*

    Now I want to add versioning info to a package:
    ~/mygo/src/geo
    ====================================
    package geo
    var VERSION string
    var MinVersion string

    func GetVERSION() string {
    return fmt.Sprintf("%s:%s%s", "geo", VERSION, MinVersion)
    }
    ====================================
    ================
    Install package
    ================
    go install -ldflags "-X geo.VERSION 'v.1' -X geo.MinVersion `date -u
    +.%Y:%m:%d.%H:%M:%S`"
    go install a package won't invoke ld, so -ldflags won't be used.

    i'm afraid you must embed your version when building the main executable as
    only then
    is ld invoked and -ldflags used.
    ================

    ================
    // MyApp.go
    ================
    package main
    import (
    "geo"
    "fmt"
    "os"
    )

    func main() {
    fmt.Printf("\n%s\n", geo.GetVERSION())
    }

    ================
    Build
    ================
    go build MyApp.go
    ================

    Run
    ================
    ./MyApp
    ================

    *geo.GetVERSION() is returning empty string.*

    What I am missing?
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Constantine Vass at Oct 27, 2013 at 5:13 pm
    I understand now.

    What best practice you recommend for versioning?

    How to make something like this:
    ver. 1.0.1
    ver. 1.0.2

    So every time a build is made the last number to increase automatically?

    On Saturday, October 26, 2013 8:27:25 PM UTC-7, minux wrote:


    On Sat, Oct 26, 2013 at 4:58 PM, Constantine Vass <ths...@gmail.com<javascript:>
    wrote:

    I am adding versioning info to may main app:
    ====================================
    ================
    // MyApp.go
    ================
    package main
    import (
    "geo"
    "fmt"
    "os"
    )
    var VERSION string
    var MinVersion string

    func main() {
    RunName := os.Args[0]
    fmt.Printf("\nRunName=%s VERSION=%s%s--------------------\n", RunName,
    VERSION, MinVersion)
    }
    ================


    ================
    Build
    ================
    go build -ldflags "-X main.VERSION 'v.1' -X main.MinVersion `date -u
    +.%Y:%m:%d.%H:%M:%S`" MyApp.go
    ================

    Run
    ================
    ./MyApp
    ================

    RunName=./MyApp VERSION=v.1.2013:10:26.20:48:37--------------------

    ====================================

    *This is working fine.*

    Now I want to add versioning info to a package:
    ~/mygo/src/geo
    ====================================
    package geo
    var VERSION string
    var MinVersion string

    func GetVERSION() string {
    return fmt.Sprintf("%s:%s%s", "geo", VERSION, MinVersion)
    }
    ====================================
    ================
    Install package
    ================
    go install -ldflags "-X geo.VERSION 'v.1' -X geo.MinVersion `date -u
    +.%Y:%m:%d.%H:%M:%S`"
    go install a package won't invoke ld, so -ldflags won't be used.

    i'm afraid you must embed your version when building the main executable
    as only then
    is ld invoked and -ldflags used.
    ================

    ================
    // MyApp.go
    ================
    package main
    import (
    "geo"
    "fmt"
    "os"
    )

    func main() {
    fmt.Printf("\n%s\n", geo.GetVERSION())
    }

    ================
    Build
    ================
    go build MyApp.go
    ================

    Run
    ================
    ./MyApp
    ================

    *geo.GetVERSION() is returning empty string.*

    What I am missing?
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Volker Dobler at Oct 27, 2013 at 5:19 pm
    make and sed?

    V.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 26, '13 at 8:58p
activeOct 27, '13 at 5:19p
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase