Skip to content

Commit

Permalink
gofmt and govet code, read and contributors update
Browse files Browse the repository at this point in the history
  • Loading branch information
lacion committed Dec 9, 2019
1 parent 0f67fbe commit d5f0964
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 42 deletions.
2 changes: 1 addition & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
- Tim Mathews [timmathew](https://github.com/timmathews)
- Matthew Riedel [mkriedel](https://github.com/mkriedel)
- Walter Scheper [wfscheper](https://github.com/wfscheper)
- Walter Schepe [jrnt30](https://github.com/jrnt30)
- Justin Nauman [jrnt30](https://github.com/jrnt30)
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Change Log
All enhancements and patches to Cookiecutter Golang will be documented in this file.

## [2019-12-09]
### changed
- updated golang docker base image version options
- made go mod the default option
- updated for gofmt -s format
- updated code to be go vet valid
- updated readme and contributors

## [2019-04-18]
### changed
- updated golang docker base image version options
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Powered by [Cookiecutter](https://github.com/audreyr/cookiecutter), Cookiecutter

## Constraints

- Uses `dep` for dependency management
- Uses `dep` or `mod` for dependency management
- Only maintained 3rd party libraries are used.

This project now uses docker multistage builds, you need at least docker version v17.05.0-ce to use the docker file in this template, [you can read more about multistage builds here](https://www.critiqus.com/post/multi-stage-docker-builds/).
Expand Down
4 changes: 2 additions & 2 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"docker_hub_username": "lacion",
"docker_image": "lacion/alpine-base-image:latest",
"docker_build_image": "lacion/alpine-golang-buildimage",
"docker_build_image_version": ["1.12.4", "1.11.9", "1.10.8", "1.9.7"],
"go_mod_or_dep": ["dep", "mod"],
"docker_build_image_version": ["1.13", "1.12.9", "1.11.9"],
"go_mod_or_dep": ["mod", "dep"],
"use_docker": "y",
"use_git": "y",
"use_logrus_logging": "y",
Expand Down
37 changes: 19 additions & 18 deletions {{cookiecutter.app_name}}/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
package cmd

import (
"fmt"
"os"
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/spf13/cobra"
)

var cfgFile string

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "{{cookiecutter.app_name}}",
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely contains
Use: "generated code example",
Short: "A brief description of your application",
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) { },
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
}

// 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.
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

func init() {
cobra.OnInitialize()
cobra.OnInitialize()

// Cobra also supports local flags, which will only run
// when this action is called directly.
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
// Cobra also supports local flags, which will only run
// when this action is called directly.
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

}
30 changes: 15 additions & 15 deletions {{cookiecutter.app_name}}/cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package cmd

import (
"github.com/spf13/cobra"
"fmt"
"github.com/{{cookiecutter.github_username}}/{{cookiecutter.app_name}}/version"
"fmt"
"github.com/lacion/cookiecutter_golang_example/version"
"github.com/spf13/cobra"
)

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of {{cookiecutter.app_name}}",
Long: `All software has versions. This is {{cookiecutter.app_name}}`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Build Date:", version.BuildDate)
fmt.Println("Git Commit:", version.GitCommit)
fmt.Println("Version:", version.Version)
fmt.Println("Go Version:", version.GoVersion)
fmt.Println("OS / Arch:", version.OsArch)
},
Use: "version",
Short: "Print the version number of generated code example",
Long: `All software has versions. This is generated code example`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Build Date:", version.BuildDate)
fmt.Println("Git Commit:", version.GitCommit)
fmt.Println("Version:", version.Version)
fmt.Println("Go Version:", version.GoVersion)
fmt.Println("OS / Arch:", version.OsArch)
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}
rootCmd.AddCommand(versionCmd)
}
2 changes: 2 additions & 0 deletions {{cookiecutter.app_name}}/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ type Provider interface {

var defaultConfig *viper.Viper

// Config returns a default config providers
func Config() Provider {
return defaultConfig
}

// LoadConfigProvider returns a configured viper instance
func LoadConfigProvider(appName string) Provider {
return readViperConfig(appName)
}
Expand Down
6 changes: 6 additions & 0 deletions {{cookiecutter.app_name}}/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ func init() {
}

{% if cookiecutter.use_viper_config == "y" %}
// NewLogger returns a configured logrus instance
func NewLogger(cfg config.Provider) *logrus.Logger {
return newLogrusLogger(cfg)
}
{% else %}
// NewLogger returns logrus instance
func NewLogger() *logrus.Logger {
return newLogrusLogger()
}
Expand Down Expand Up @@ -78,20 +80,24 @@ func newLogrusLogger() *logrus.Logger {
return l
}

// Fields is a map string interface to define fields in the structured log
type Fields map[string]interface{}

// With allow us to define fields in out structured logs
func (f Fields) With(k string, v interface{}) Fields {
f[k] = v
return f
}

// WithFields allow us to define fields in out structured logs
func (f Fields) WithFields(f2 Fields) Fields {
for k, v := range f2 {
f[k] = v
}
return f
}

// WithFields allow us to define fields in out structured logs
func WithFields(fields Fields) Logger {
return defaultLogger.WithFields(logrus.Fields(fields))
}
Expand Down
13 changes: 8 additions & 5 deletions {{cookiecutter.app_name}}/version/version.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package version

import (
"runtime"
"fmt"
"fmt"
"runtime"
)

// The git commit that was compiled. This will be filled in by the compiler.
// GitCommit returns the git commit that was compiled. This will be filled in by the compiler.
var GitCommit string

// The main version number that is being run at the moment.
// Version returns the main version number that is being run at the moment.
const Version = "0.1.0"

// BuildDate returns the date the binary was built
var BuildDate = ""

// GoVersion returns the version of the go runtime used to compile the binary
var GoVersion = runtime.Version()

var OsArch = fmt.Sprintf("%s %s", runtime.GOOS, runtime.GOARCH)
// OsArch returns the os and arch used to build the binary
var OsArch = fmt.Sprintf("%s %s", runtime.GOOS, runtime.GOARCH)

0 comments on commit d5f0964

Please sign in to comment.