Skip to content

Commit

Permalink
Merge pull request #7 from duckbunny/golint
Browse files Browse the repository at this point in the history
imporved golinting
  • Loading branch information
jasonrichardsmith committed May 21, 2016
2 parents 404d367 + f0f944c commit e5ad563
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .godocdown.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Is the basic template to define microservices in json and yaml format.

[![GoDoc](https://godoc.org/github.com/duckbunny/{{ .Name }}?status.svg)](https://godoc.org/github.com/duckbunny/{{ .Name }})
[![Build Status](https://travis-ci.org/duckbunny/service.svg?branch=master)](https://travis-ci.org/duckbunny/service)
[![Coverage Status](https://coveralls.io/repos/github/duckbunny/service/badge.svg?branch=githubtesting)](https://coveralls.io/github/duckbunny/service?branch=githubtesting)
[![Coverage Status](https://coveralls.io/repos/github/duckbunny/service/badge.svg?branch=master)](https://coveralls.io/github/duckbunny/service?branch=master)
{{ .EmitHeader }}

{{ .EmitSynopsis }}
Expand Down
51 changes: 30 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Is the basic template to define microservices in json and yaml format.
--
import "github.com/duckbunny/service"

Service is the definition of the microservice.
Package service is the definition of the microservice.

The Service definition is used to automate bootstrap microservices, automate
communication between separate services and to provide a human readable
Expand All @@ -18,6 +18,15 @@ definition of a service.

## Usage

```go
var (
//ErrNoPort when no port has been set for service
ErrNoPort = errors.New("No port set")
//ErrNoHost when no host has been set for service
ErrNoHost = errors.New("No host set")
)
```

#### type Config

```go
Expand Down Expand Up @@ -45,51 +54,51 @@ Configs represents a slice of configs

```go
type Flag struct {
// The flag designation for the command line flag.
// Key is the flag designation for the command line flag.
Key string `json:"key" yaml:"Key"`

// An environment variable that can bes set in lieu of the flag.
// Env is an environment variable that can bes set in lieu of the flag.
// CLI flag always overrides environment variable.
Env string `json:"env" yaml:"Env"`

// Human readable description of the flag.
// Description is the human readable description of the flag.
Description string `json:"description" yaml:"Description"`

// Defines flas as required.
// Required defines flag as required.
Required bool `json:"required" yaml:"Required"`
}
```

Represents a sincle command line flag.
Flag represents a single command line flag.

#### type Flags

```go
type Flags []Flag
```

Represents a slice of Flags.
Flags represents a slice of Flags.

#### func (Flags) GetFlag

```go
func (fs Flags) GetFlag(key string) (Flag, error)
```
Get Flag by key.
GetFlag by key.

#### func (Flags) Required

```go
func (fs Flags) Required() []Flag
```
Return a slice required flags.
Required returns a slice required flags.

#### func (Flags) RequiredKeys

```go
func (fs Flags) RequiredKeys() []string
```
Return a slice required flag keys.
RequiredKeys returns a slice required flag keys.

#### type Parameter

Expand Down Expand Up @@ -126,28 +135,28 @@ Parameter defines a single parameter for the service to be called.
type Parameters []Parameter
```

Represents a slice of parameters
Parameters represents a slice of parameters

#### func (Parameters) GetParameter

```go
func (ps Parameters) GetParameter(key string) (Parameter, error)
```
Get Paramater by key.
GetParameter by key.

#### func (Parameters) Required

```go
func (ps Parameters) Required() []Parameter
```
Return a slice required parameters.
Required returns a slice required parameters.

#### func (Parameters) RequiredKeys

```go
func (ps Parameters) RequiredKeys() []string
```
Return a slice required parameter keys.
RequiredKeys returns a slice of required parameter keys.

#### type Response

Expand Down Expand Up @@ -223,46 +232,46 @@ Service definition
```go
func LoadFromFile(file string) (*Service, error)
```
Shortcut to get new Service from yaml service definition file.
LoadFromFile gets a new Service from yaml service definition file.

#### func LoadFromJSON

```go
func LoadFromJSON(js []byte) (*Service, error)
```
Shortcut to new Service from json bytes service definition
LoadFromJSON loads to new Service from json bytes service definition

#### func New

```go
func New() *Service
```
Get a new Service.
New get a new Service.

#### func This

```go
func This() (*Service, error)
```
Shortcut to load Service for this application.
This shortcuts to load Service for this application.

#### func (*Service) LoadFromFile

```go
func (s *Service) LoadFromFile(file string) error
```
Load yaml service definition file into current service.
LoadFromFile loads yaml service definition file into current service.

#### func (*Service) LoadFromJSON

```go
func (s *Service) LoadFromJSON(js []byte) error
```
Load json service definition into current Service
LoadFromJSON loads service definition into current Service

#### func (*Service) ToJSON

```go
func (s *Service) ToJSON() ([]byte, error)
```
Load json service definition into current Service
ToJSON converst current service to json
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// license that can be found in the LICENSE file.

/*
Service is the definition of the microservice.
Package service is the definition of the microservice.
The Service definition is used to automate bootstrap microservices,
automate communication between separate services and to provide a human
Expand Down
42 changes: 22 additions & 20 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ var (
)

var (
//ErrNoPort when no port has been set for service
ErrNoPort = errors.New("No port set")
//ErrNoHost when no host has been set for service
ErrNoHost = errors.New("No host set")
)

Expand Down Expand Up @@ -81,13 +83,13 @@ type Service struct {
Host string `json:"-" yaml:"-"`
}

// Get a new Service.
// New get a new Service.
func New() *Service {
service := new(Service)
return service
}

// Shortcut to load Service for this application.
// This shortcuts to load Service for this application.
func This() (*Service, error) {
if !flag.Parsed() {
flag.Parse()
Expand All @@ -107,14 +109,14 @@ func This() (*Service, error) {
return s, err
}

// Shortcut to get new Service from yaml service definition file.
// LoadFromFile gets a new Service from yaml service definition file.
func LoadFromFile(file string) (*Service, error) {
s := New()
err := s.LoadFromFile(file)
return s, err
}

// Load yaml service definition file into current service.
// LoadFromFile loads yaml service definition file into current service.
func (s *Service) LoadFromFile(file string) error {
_, err := os.Stat(file)
if err == nil {
Expand All @@ -131,27 +133,27 @@ func (s *Service) LoadFromFile(file string) error {
return err
}

// Shortcut to new Service from json bytes service definition
// LoadFromJSON loads to new Service from json bytes service definition
func LoadFromJSON(js []byte) (*Service, error) {
s := New()
err := s.LoadFromJSON(js)
return s, err
}

// Load json service definition into current Service
// LoadFromJSON loads service definition into current Service
func (s *Service) LoadFromJSON(js []byte) error {
return json.Unmarshal(js, s)
}

// Load json service definition into current Service
// ToJSON converst current service to json
func (s *Service) ToJSON() ([]byte, error) {
return json.Marshal(s)
}

// Represents a slice of parameters
// Parameters represents a slice of parameters
type Parameters []Parameter

// Return a slice required parameter keys.
// RequiredKeys returns a slice of required parameter keys.
func (ps Parameters) RequiredKeys() []string {
var required []string
for _, p := range ps {
Expand All @@ -162,7 +164,7 @@ func (ps Parameters) RequiredKeys() []string {
return required
}

// Return a slice required parameters.
// Required returns a slice required parameters.
func (ps Parameters) Required() []Parameter {
var required []Parameter
for _, p := range ps {
Expand All @@ -173,7 +175,7 @@ func (ps Parameters) Required() []Parameter {
return required
}

// Get Paramater by key.
// GetParameter by key.
func (ps Parameters) GetParameter(key string) (Parameter, error) {
for _, p := range ps {
if p.Key == key {
Expand Down Expand Up @@ -232,10 +234,10 @@ type Response struct {
DataType string `json:"dataType" yaml:"DataType"`
}

// Represents a slice of Flags.
// Flags represents a slice of Flags.
type Flags []Flag

// Return a slice required flag keys.
// RequiredKeys returns a slice required flag keys.
func (fs Flags) RequiredKeys() []string {
var required []string
for _, f := range fs {
Expand All @@ -246,7 +248,7 @@ func (fs Flags) RequiredKeys() []string {
return required
}

// Return a slice required flags.
// Required returns a slice required flags.
func (fs Flags) Required() []Flag {
var required []Flag
for _, f := range fs {
Expand All @@ -257,7 +259,7 @@ func (fs Flags) Required() []Flag {
return required
}

// Get Flag by key.
// GetFlag by key.
func (fs Flags) GetFlag(key string) (Flag, error) {
for _, f := range fs {
if f.Key == key {
Expand All @@ -267,18 +269,18 @@ func (fs Flags) GetFlag(key string) (Flag, error) {
return Flag{}, fmt.Errorf("Flag %v not found", key)
}

// Represents a sincle command line flag.
// Flag represents a single command line flag.
type Flag struct {
// The flag designation for the command line flag.
// Key is the flag designation for the command line flag.
Key string `json:"key" yaml:"Key"`

// An environment variable that can bes set in lieu of the flag.
// Env is an environment variable that can bes set in lieu of the flag.
// CLI flag always overrides environment variable.
Env string `json:"env" yaml:"Env"`

// Human readable description of the flag.
// Description is the human readable description of the flag.
Description string `json:"description" yaml:"Description"`

// Defines flas as required.
// Required defines flag as required.
Required bool `json:"required" yaml:"Required"`
}

0 comments on commit e5ad563

Please sign in to comment.