minke-generator-go 0.1.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e44687462591b411096667b256f5a6a967e180bb
4
- data.tar.gz: 626f70ea6aea969c00d05843eb4046544c764253
3
+ metadata.gz: 919e1b5d93dbcbc2fa3add6dc68e6f44376982fa
4
+ data.tar.gz: ecdf27932dca828d8f6b296a5e61450815c5ea93
5
5
  SHA512:
6
- metadata.gz: ac815ffe9b0ceaa97e06c66747e220b9b1eb7763f6286bbbbae94cb25d41967f87948956a78c0b7b7825987c184f7c04f62dff27ab6deba36b5fcbfa8235b004
7
- data.tar.gz: fbab9123fea841605fb665ef1e6ee4cd6ff4ef133ad0857e2269ccd99e81fed539c7d4283d6c085fd4af32f7b591e3cf656a0aa70cfe95f6bffb08c4eef9e391
6
+ metadata.gz: 31fa9cf1b50555a864c418319025a583b90d5bdc850c32e42e1ceaa7ea9272e442f0f6528dbd6e5b884c41cc8020271ff52415b7b96b7f2ed552b3c72e72902c
7
+ data.tar.gz: 3ba77bc89cbeb323f0777b963a8d43cce073e2606be5006e72a47ff259d17000d0080b3b46ee007b25d73f3a3bdc330e91606beede23c92a247c5b71b135df1b
data/.gitignore CHANGED
@@ -7,3 +7,6 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .DS_Store
11
+ *.iml
12
+ .idea/
data/README.md CHANGED
@@ -2,41 +2,62 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/nicholasjackson/minke-generator-go.svg?branch=master)](https://travis-ci.org/nicholasjackson/minke-generator-go)
4
4
 
5
- This generator creates a REST API microservice in Golang.
5
+ This generator creates a REST API Microservice in Go for the Minke build and test system.
6
6
 
7
- ## Available variables for template (erb style)
8
- - <%= application_name %>: The name of the application executable
9
- - <%= namespace %>: Namespace of the application
7
+ For information on Minke please see the documentation [http://nicholasjackson.github.io/minke/](http://nicholasjackson.github.io/minke/).
10
8
 
11
- ## Testing your template
12
- ```
13
- $ bundle
14
- ```
15
-
16
- Test your generator by running ...
17
- ```
18
- $ bundle exec minke -g minke-generator-template -o ../temp -a tester -n mynamespace
19
- ```
9
+ ## Available variables for templates (erb style)
10
+ | Variable | Description |
11
+ | ----------------------- | |
12
+ | <%= application_name %> | The name of the application executable |
13
+ | <%= namespace %> | Namespace of the application |
14
+ | <%= src_root %> | Source root of the application |
20
15
 
21
16
  ## Installation
22
17
 
23
18
  Add this line to your application's Gemfile:
24
19
 
25
20
  ```ruby
26
- gem 'minke-generator-template'
21
+ gem 'minke'
22
+ gem 'minke-generator-go'
27
23
  ```
28
24
 
29
25
  And then execute:
30
26
 
31
27
  $ bundle
32
28
 
33
- Or install it yourself as:
29
+ Or install it yourself:
30
+
31
+ ```
32
+ $ gem install minke
33
+ $ gem install minke-generator-go
34
34
 
35
- $ gem install minke-generator-template
35
+ ```
36
36
 
37
37
  ## Usage
38
38
 
39
- TODO: Write usage instructions here
39
+ To scaffold a new service run:
40
+
41
+ ```bash
42
+ $ minke -g minke-generator-go -o $GOPATH/src/github.com/nicholasjackson/helloworld
43
+ -a helloworld -n github.com/nicholasjackson
44
+ ```
45
+
46
+ ## Build and test with Docker
47
+ To run a build with a Docker container, to execute the functional and unit tests you can use the following commands. Please see the main Minke documentation for more information [http://nicholasjackson.github.io/minke/](http://nicholasjackson.github.io/minke/).
48
+
49
+ ### Build Application Code and Execute Unit tests
50
+ ```bash
51
+ $ cd _build
52
+ $ bundle
53
+ $ rake app:test
54
+ ```
55
+
56
+ ### Build a Docker image and execute functional tests with Cucumber
57
+ ```bash
58
+ $ rake app:build_image
59
+ $ rake app:cucumber
60
+ ```
40
61
 
41
62
  ## Development
42
63
 
@@ -46,7 +67,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
46
67
 
47
68
  ## Contributing
48
69
 
49
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/minke-generator-template. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nicholasjackson/minke-generator-netmvc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
50
71
 
51
72
 
52
73
  ## License
@@ -4,8 +4,8 @@ gem "rake"
4
4
  gem 'cucumber-api', '~> 0.3'
5
5
  gem 'nokogiri'
6
6
 
7
- #gem 'minke'
8
- #gem 'minke-generator-go'
7
+ gem 'minke'
8
+ gem 'minke-generator-go'
9
9
 
10
- gem 'minke', :path => '/Users/nicj/Developer/gems/minke'
11
- gem 'minke-generator-go', :path => '/Users/nicj/Developer/gems/minke-generator-go'
10
+ #gem 'minke', :path => '/Users/nicj/Developer/gems/minke'
11
+ #gem 'minke-generator-go', :path => '/Users/nicj/Developer/gems/minke-generator-go'
@@ -13,6 +13,9 @@ docker:
13
13
  application_docker_file: './dockerfile/<%= application_name %>/'
14
14
  application_compose_file: './dockercompose/<%= application_name %>/docker-compose.yml'
15
15
  fetch:
16
+ enabled: true
17
+ test:
18
+ enabled: true
16
19
  build:
17
20
  post:
18
21
  copy:
@@ -30,7 +33,6 @@ run:
30
33
  address: consul
31
34
  port: 8500
32
35
  type: private
33
- test:
34
36
  cucumber:
35
37
  pre:
36
38
  consul_loader:
@@ -1,4 +1,5 @@
1
1
  version: '2'
2
+
2
3
  services:
3
4
  <%= application_name %>:
4
5
  image: <%= application_name %>
@@ -9,6 +10,7 @@ services:
9
10
  links:
10
11
  - consul:consul
11
12
  - statsd:statsd
13
+ - syslog:syslog
12
14
  consul:
13
15
  image: progrium/consul
14
16
  ports:
@@ -22,7 +24,7 @@ services:
22
24
  expose:
23
25
  - "8125/udp"
24
26
  environment:
25
- - "SERVICE_NAME=statsd"
27
+ - "SERVICE_8125_NAME=statsd-8125"
26
28
  registrator:
27
29
  image: 'gliderlabs/registrator:latest'
28
30
  links:
@@ -30,3 +32,8 @@ services:
30
32
  command: '-internal -tags=dev consul://consul:8500'
31
33
  volumes:
32
34
  - '/var/run/docker.sock:/tmp/docker.sock'
35
+ syslog:
36
+ image: 'factorish/syslog'
37
+ command: '-t udp'
38
+ environment:
39
+ - "SERVICE_514_NAME=syslog-514"
@@ -1,4 +1,5 @@
1
1
  version: '2'
2
+
2
3
  services:
3
4
  consul:
4
5
  image: progrium/consul
@@ -13,13 +14,16 @@ services:
13
14
  expose:
14
15
  - "8125/udp"
15
16
  environment:
16
- - "SERVICE_NAME=statsd"
17
+ - "SERVICE_8125_NAME=statsd-8125"
17
18
  registrator:
18
19
  image: 'gliderlabs/registrator:latest'
19
20
  links:
20
21
  - consul:consul
21
- environment:
22
- - "SERVICE_NAME=statsd"
23
22
  command: '-internal -tags=dev consul://consul:8500'
24
23
  volumes:
25
24
  - '/var/run/docker.sock:/tmp/docker.sock'
25
+ syslog:
26
+ image: 'factorish/syslog'
27
+ command: '-t udp'
28
+ environment:
29
+ - "SERVICE_514_NAME=syslog-514"
@@ -1,3 +1,4 @@
1
1
  {
2
- "stats_d_server": "{{key "<%= application_name %>/Settings/statsd/host"}}:{{key "<%= application_name %>/Settings/statsd/port"}}"
2
+ "stats_d_server": "{{range service "statsd-8125"}}{{.Address}}:{{.Port}}{{end}}",
3
+ "syslog_server": "{{range $index, $element := service "syslog-514"}}{{if eq $index 0}}{{.Address}}:{{.Port}}{{end}}{{end}}"
3
4
  }
@@ -8,6 +8,7 @@ import (
8
8
 
9
9
  type ConfigStruct struct {
10
10
  StatsDServerIP string `json:"stats_d_server"`
11
+ SysLogIP string `json:"syslog_server"`
11
12
  RootFolder string
12
13
  }
13
14
 
@@ -4,6 +4,7 @@ import (
4
4
  "encoding/json"
5
5
  "fmt"
6
6
  "net/http"
7
+ "log"
7
8
 
8
9
  "github.com/gorilla/context"
9
10
  "<%= namespace %>/<%= application_name %>/logging"
@@ -11,9 +12,11 @@ import (
11
12
 
12
13
  type EchoDependenciesContainer struct {
13
14
  StatsD logging.StatsD `inject:"statsd"`
15
+ Log *log.Logger `inject:""`
14
16
  }
15
17
 
16
18
  var EchoDependencies *EchoDependenciesContainer = &EchoDependenciesContainer{}
19
+ const EHTAGNAME = "EchoHandler: "
17
20
 
18
21
  // use the validation middleware to automatically validate input
19
22
  // github.com/asaskevich/govalidator
@@ -23,6 +26,7 @@ type Echo struct {
23
26
 
24
27
  func EchoHandler(rw http.ResponseWriter, r *http.Request) {
25
28
  EchoDependencies.StatsD.Increment(ECHO_HANDLER + POST + CALLED)
29
+ EchoDependencies.Log.Printf("%v Called GET\n", EHTAGNAME)
26
30
 
27
31
  // request is set into the context from the middleware
28
32
  request := context.Get(r, "request").(*Echo)
@@ -27,6 +27,7 @@ func echoTestSetup(t *testing.T) {
27
27
  err := g.Provide(
28
28
  &inject.Object{Value: EchoDependencies},
29
29
  &inject.Object{Value: echoStatsDMock, Name: "statsd"},
30
+ &inject.Object{Value: log.New(os.Stdout, "tester", log.Lshortfile)},
30
31
  )
31
32
 
32
33
  if err != nil {
@@ -3,6 +3,7 @@ package handlers
3
3
  import (
4
4
  "encoding/json"
5
5
  "net/http"
6
+ "log"
6
7
 
7
8
  "<%= namespace %>/<%= application_name %>/logging"
8
9
  )
@@ -31,6 +32,9 @@ type HealthDependenciesContainer struct {
31
32
  // statsD interface must use a name type as injection cannot infer ducktypes
32
33
  Stats logging.StatsD `inject:"statsd"`
33
34
 
35
+ // reference to the log writer
36
+ Log *log.Logger `inject:""`
37
+
34
38
  // if not specified in the graph will automatically create private instance
35
39
  PrivateBuilder *HealthResponseBuilder `inject:"private"`
36
40
  }
@@ -40,10 +44,12 @@ type HealthResponse struct {
40
44
  }
41
45
 
42
46
  var HealthDependencies *HealthDependenciesContainer = &HealthDependenciesContainer{}
47
+ const HHTAGNAME = "HealthHandler: "
43
48
 
44
49
  func HealthHandler(rw http.ResponseWriter, r *http.Request) {
45
50
  // all HealthHandlerDependencies are automatically created by injection process
46
51
  HealthDependencies.Stats.Increment(HEALTH_HANDLER + GET + CALLED)
52
+ HealthDependencies.Log.Printf("%v Called GET\n", HHTAGNAME)
47
53
 
48
54
  response := HealthDependencies.SingletonBuilder.SetStatusMessage("OK").Build()
49
55
 
@@ -25,6 +25,7 @@ func healthTestSetup(t *testing.T) {
25
25
  err := g.Provide(
26
26
  &inject.Object{Value: HealthDependencies},
27
27
  &inject.Object{Value: healthStatsDMock, Name: "statsd"},
28
+ &inject.Object{Value: log.New(os.Stdout, "tester", log.Lshortfile)},
28
29
  )
29
30
 
30
31
  if err != nil {
@@ -4,6 +4,8 @@ import (
4
4
  "fmt"
5
5
  "net/http"
6
6
  "os"
7
+ "log"
8
+ "log/syslog"
7
9
  "<%= namespace %>/<%= application_name %>/global"
8
10
  "<%= namespace %>/<%= application_name %>/handlers"
9
11
 
@@ -38,11 +40,19 @@ func setupInjection() {
38
40
  panic(fmt.Sprintln("Unable to create StatsD Client: ", err))
39
41
  }
40
42
 
43
+ syslogWriter, err := syslog.Dial("udp", global.Config.SysLogIP, syslog.LOG_SYSLOG, "sorcery")
44
+ if err != nil {
45
+ panic(fmt.Sprintln("Unable to connect to syslog: ", err))
46
+ }
47
+
48
+ logWriter := log.New(syslogWriter, "<%= application_name %>: ", log.Lshortfile)
49
+
41
50
  err = g.Provide(
42
51
  &inject.Object{Value: handlers.RouterDependencies},
43
52
  &inject.Object{Value: handlers.HealthDependencies},
44
53
  &inject.Object{Value: handlers.EchoDependencies},
45
54
  &inject.Object{Value: statsdClient, Name: "statsd"},
55
+ &inject.Object{Value: logWriter},
46
56
  )
47
57
 
48
58
  if err != nil {
@@ -1,7 +1,7 @@
1
1
  module Minke
2
2
  module Generators
3
3
  module GoMicroservice
4
- VERSION = "0.1.0"
4
+ VERSION = "0.4.0"
5
5
  end
6
6
  end
7
7
  end
@@ -12,16 +12,18 @@ module Minke
12
12
  config.template_location = File.expand_path(File.dirname(__FILE__)) + '/gomicroservice/scaffold'
13
13
 
14
14
  config.build_settings = Minke::Generators::BuildSettings.new
15
+
15
16
  config.build_settings.build_commands = Minke::Generators::BuildCommands.new.tap do |bc|
16
17
  bc.fetch = [['/bin/bash', '-c', 'go get -t -v -d ./... && echo Downloaded packages']]
17
18
  bc.build = [['/bin/bash', '-c', 'go build -a -installsuffix cgo -ldflags \'-s\' -o <%= application_name %>']]
18
19
  bc.test = [['/bin/bash', '-c', 'go test ./...']]
19
20
  end
21
+
20
22
  config.build_settings.docker_settings = Minke::Generators::DockerSettings.new.tap do |bs|
21
23
  bs.image = 'golang:latest'
22
24
  bs.env = ['CGO_ENABLED=0']
23
25
  bs.binds = ["#{ENV['GOPATH']}/src:/go/src"]
24
- #bs.working_directory = 'sdsds'#{}"#{self.working_directory}"
26
+ # working directory is added via a class patch to enable lazy load
25
27
  end
26
28
 
27
29
  # we need lazy evaluation of this property
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minke-generator-go
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nic Jackson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-19 00:00:00.000000000 Z
11
+ date: 2016-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  requirements: []
134
134
  rubyforge_project:
135
- rubygems_version: 2.5.1
135
+ rubygems_version: 2.6.4
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: Go microservice template for Minke