Using binary packages directly

后端 未结 4 1315
情深已故
情深已故 2020-12-08 11:22

I\'m writing a library in Go. I\'m planning to distribute it, and with a main requirement of \'without source codes\'.

For testing, I have created

4条回答
  •  不知归路
    2020-12-08 11:59

    The binary-only packages is supported in go 1.7 now.

    You can only provide .a files and fake go files without source code to distribute it now.

    Here is a detailed example and a script of Go1.7 binary package generator.

    myframework/frameImplement.go

    package myframework
    
    import "fmt"
    
    func Hello(name string) string {
        return fmt.Sprintf("Hello, %s!", name)
    }
    

    main/main.go

    package main
    
    import (
        "fmt"
        "golang-binary-package-generator/myframework"
    )
    
    func main() {
        fmt.Println(" start program ")
        fmt.Println(" print program :", myframework.Hello("print something now"))
    }
    

    If I want to hide my framework's source code, just build it with go build -i -o $GOPATH/pkg/framework.a, then modify your source code to

    //go:binary-only-package
    
    package framework
    
    //you can add function prototype here for go doc etc, but no necessary.
    

    , which you can use my binary package generator(script) to help you.

提交回复
热议问题