Skip to content

Commit

Permalink
feat(build): use ldflags to set version (#10)
Browse files Browse the repository at this point in the history
* feat(build): embed version via ldflags

* fix(gobuilder): fix config
  • Loading branch information
slavovojacek authored Jul 31, 2021
1 parent 74f3abc commit 48f4ed8
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
builds:
-
ldflags:
- -s -w -X github.com/sniptt-official/ots/build.Version={{.Version}}
15 changes: 14 additions & 1 deletion api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"net/http"
"net/url"
"time"

"github.com/sniptt-official/ots/build"
)

type CreateOtsReq struct {
Expand Down Expand Up @@ -51,8 +53,19 @@ func CreateOts(encryptedBytes []byte, expiresIn time.Duration) (*CreateOtsRes, e
return nil, err
}

client := &http.Client{}

// TODO: Make URL part of config
res, err := http.Post("https://api.ots.sniptt.com/secrets", "application/json", payloadBuf)
req, err := http.NewRequest("POST", "https://api.ots.sniptt.com/secrets", payloadBuf)
if err != nil {
return nil, err
}

req.Header.Add("Content-Type", "application/json")
req.Header.Add("X-Client-Name", "ots-cli")
req.Header.Add("X-Client-Version", build.Version)

res, err := client.Do(req)
if err != nil {
return nil, err
}
Expand Down
19 changes: 19 additions & 0 deletions build/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Copyright © 2021 Sniptt <support@sniptt.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package build

// Will be changed at build time via -ldflags
var Version = "debug"
37 changes: 20 additions & 17 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,30 @@ import (
"fmt"
"os"

"github.com/sniptt-official/ots/build"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var cfgFile string

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "ots",
Short: "Easily create and share end-to-end encrypted secrets with others",
// Long: `A longer description that spans multiple lines and likely contains
// examples and usage of using your application. For example:

// Cobra is a CLI library for Go that empowers applications.
// This application is a tool to generate the needed files
// to quickly create a Cobra application.`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
Version: "0.0.7",
}
var (
cfgFile string

// rootCmd represents the base command when called without any subcommands
rootCmd = &cobra.Command{
Use: "ots",
Short: "Easily create and share end-to-end encrypted secrets with others",
// Long: `A longer description that spans multiple lines and likely contains
// examples and usage of using your application. For example:

// Cobra is a CLI library for Go that empowers applications.
// This application is a tool to generate the needed files
// to quickly create a Cobra application.`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
Version: build.Version,
}
)

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
Expand Down

0 comments on commit 48f4ed8

Please sign in to comment.