Skip to content

Commit

Permalink
Go fmt, go lint project, Add travis
Browse files Browse the repository at this point in the history
  • Loading branch information
Kujtim committed Sep 29, 2017
1 parent 27db19f commit f83a92c
Show file tree
Hide file tree
Showing 19 changed files with 318 additions and 273 deletions.
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
language: go

env:
- COVERALLS_TOKEN=sW1SPRRXgQPGUiUmt43mTkMUzrsyqIBY7

before_install:
- go get github.com/mattn/goveralls
- go get github.com/modocache/gover
- go get github.com/Masterminds/glide
install:
- glide install
script:
- go test -race -v ./...
- ./coveralls.bash
go:
- 1.9.x
3 changes: 1 addition & 2 deletions cmd/g_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ var initserviceCmd = &cobra.Command{
return
}
}
emw := false
smw := false
var emw, smw bool
if viper.GetBool("g_s_dmw") {
emw = true
smw = true
Expand Down
4 changes: 2 additions & 2 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
)

var generateCmd = &cobra.Command{
Use: "generate",
Short: "A set of useful generators",
Use: "generate",
Short: "A set of useful generators",
Aliases: []string{"g"},
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
Expand Down
7 changes: 4 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"fmt"
"os"
"os/exec"
"runtime"
Expand All @@ -11,17 +10,19 @@ import (
"github.com/spf13/viper"
)

// RootCmd is the root command of kit
var RootCmd = &cobra.Command{
Use: "gk",
Use: "kit",
Short: "Go-Kit CLI",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}

// Execute runs the root command
func Execute() {
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
logrus.Error(err)
os.Exit(1)
}
}
Expand Down
30 changes: 30 additions & 0 deletions coveralls.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

if ! type -P gover
then
echo gover missing: go get github.com/modocache/gover
exit 1
fi

if ! type -P goveralls
then
echo goveralls missing: go get github.com/mattn/goveralls
exit 1
fi

if [[ "$COVERALLS_TOKEN" == "" ]]
then
echo COVERALLS_TOKEN not set
exit 1
fi

go list ./... | grep -v '/examples/' | cut -d'/' -f 4- | while read d
do
cd $d
go test -covermode count -coverprofile coverage.coverprofile
cd -
done

gover
goveralls -coverprofile gover.coverprofile -service travis-ci -repotoken $COVERALLS_TOKEN
find . -name '*.coverprofile' -delete
56 changes: 28 additions & 28 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,14 @@ import (
"github.com/spf13/viper"
)

type FileSystem interface {
init(dir string)
ReadFile(path string) (string, error)
WriteFile(path string, data string, force bool) error
Mkdir(path string) error
MkdirAll(path string) error
FilePathSeparator() string
Exists(path string) (bool, error)
}

var defaultFs *DefaultFs
var defaultFs *KitFs

type DefaultFs struct {
// KitFs wraps an afero.Fs
type KitFs struct {
Fs afero.Fs
}

func (f *DefaultFs) init(dir string) {
func (f *KitFs) init(dir string) {
var inFs afero.Fs
if viper.GetBool("gk_testing") {
inFs = afero.NewMemMapFs()
Expand All @@ -44,13 +35,16 @@ func (f *DefaultFs) init(dir string) {
}
}

func (f *DefaultFs) ReadFile(path string) (string, error) {
// ReadFile reads the file from `path` and returns the content in string format
// or returns an error if it occurs.
func (f *KitFs) ReadFile(path string) (string, error) {
d, err := afero.ReadFile(f.Fs, path)
return string(d), err
}

func (f *DefaultFs) WriteFile(path string, data string, force bool) error {

// WriteFile writs a file to the `path` with `data` as content, if `force` is set
// to true it will override the file if it already exists.
func (f *KitFs) WriteFile(path string, data string, force bool) error {
if b, _ := f.Exists(path); b && !(viper.GetBool("gk_force_override") || force) {
s, _ := f.ReadFile(path)
if s == data {
Expand All @@ -65,30 +59,36 @@ func (f *DefaultFs) WriteFile(path string, data string, force bool) error {
return afero.WriteFile(f.Fs, path, []byte(data), os.ModePerm)
}

func (f *DefaultFs) Mkdir(path string) error {
return f.Fs.Mkdir(path, os.ModePerm)
// Mkdir creates a directory.
func (f *KitFs) Mkdir(dir string) error {
return f.Fs.Mkdir(dir, os.ModePerm)
}

func (f *DefaultFs) MkdirAll(path string) error {
// MkdirAll creates a directory and its parents if they don't exist.
func (f *KitFs) MkdirAll(path string) error {
return f.Fs.MkdirAll(path, os.ModePerm)
}
func (f *DefaultFs) FilePathSeparator() string {
return afero.FilePathSeparator
}
func (f *DefaultFs) Exists(path string) (bool, error) {

// Exists returns true,nil if the dir/file exists or false,nil if
// the dir/file does not exist, it will return an error if something
// went wrong.
func (f *KitFs) Exists(path string) (bool, error) {
return afero.Exists(f.Fs, path)
}
func NewDefaultFs(dir string) *DefaultFs {
dfs := &DefaultFs{}

// NewDefaultFs creates a KitFs with `dir` as root.
func NewDefaultFs(dir string) *KitFs {
dfs := &KitFs{}
dfs.init(dir)
defaultFs = dfs
return dfs
}

func Get() *DefaultFs {
// Get returns a new KitFs if it was not initiated before or
// it returns the existing defaultFs if it is initiated.
func Get() *KitFs {
if defaultFs == nil {
return NewDefaultFs("")
} else {
return defaultFs
}
return defaultFs
}
Loading

0 comments on commit f83a92c

Please sign in to comment.