Skip to content

Commit

Permalink
ci: switch to GitHub Actions, bump go versions and deps (#24)
Browse files Browse the repository at this point in the history
* ci: switch to GitHub Actions, bump go versions and deps
* ci: add ci tooling to go.mod
* ci: fix spelling
  • Loading branch information
carstendietrich committed Apr 22, 2021
1 parent 76908a0 commit 6df0d34
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 49 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Tests

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.15', '1.*' ]
name: Tests
steps:
- uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- name: Get dependencies
run: go get -v -t -d ./...
- name: Test
run: CGO_ENABLED=1 go test -race ./...
static-checks:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.*' ]
name: Static checks
steps:
- uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- name: Get dependencies
run: go get -v -t -d ./...
- name: Go Vet
run: go vet ./...
- name: Go Fmt
run: |
fmt=$(gofmt -l .)
test -z $fmt || (echo "please run gofmt" ; echo $fmt ; exit 1)
- name: Go Lint
run: go run golang.org/x/lint/golint -set_exit_status $(go list ./...)
- name: Spelling
run: go run github.com/client9/misspell/cmd/misspell -error .
- name: Ineffective assignments
run: go run github.com/gordonklaus/ineffassign .
- name: Go Generate
run: |
go generate ./...
git diff --quiet || (echo 'generated go files are not up to date, check go generate, go.sum and go.mod' ; git diff ; exit 1)
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

34 changes: 17 additions & 17 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# Dingo

[![Go Report Card](https://goreportcard.com/badge/flamingo.me/dingo)](https://goreportcard.com/report/flamingo.me/dingo) [![GoDoc](https://godoc.org/flamingo.me/dingo?status.svg)](https://godoc.org/flamingo.me/dingo) [![Build Status](https://travis-ci.org/i-love-flamingo/dingo.svg)](https://travis-ci.org/i-love-flamingo/dingo)
[![Go Report Card](https://goreportcard.com/badge/flamingo.me/dingo)](https://goreportcard.com/report/flamingo.me/dingo) [![GoDoc](https://godoc.org/flamingo.me/dingo?status.svg)](https://godoc.org/flamingo.me/dingo) [![Tests](https://github.com/i-love-flamingo/dingo/workflows/Tests/badge.svg?branch=master)](https://github.com/i-love-flamingo/dingo/actions?query=branch%3Amaster+workflow%3ATests)

Dependency injection for go

## Hello Dingo

Dingo works very very similiar to [Guice](https://github.com/google/guice/wiki/GettingStarted)
Dingo works very similar to [Guice](https://github.com/google/guice/wiki/GettingStarted)

Basically one binds implementations/factories to interfaces, which are then resolved by Dingo.

Given that Dingo's idea is based on Guice we use similar examples in this documentation:

The following example shows a BillingService with two injected dependencies. Please note
that Go's nature does not allow contructors, and does not allow decorations/annotations
that Go's nature does not allow constructors, and does not allow decorations/annotations
beside struct-tags, thus, we only use struct tags (and later arguments for providers).

Also Go does not have a way to reference types (like Java's `Something.class`) we use either pointers
Also, Go does not have a way to reference types (like Java's `Something.class`) we use either pointers
or `nil` and cast it to a pointer to the interface we want to specify: `(*Something)(nil)`.
Dingo then knowns how to dereference it properly and derive the correct type `Something`.
Dingo then knows how to dereference it properly and derive the correct type `Something`.
This is not necessary for structs, where we can just use the null value via `Something{}`.

See the example folder for a complete example.
Expand Down Expand Up @@ -130,7 +130,7 @@ Dingo will provide you with an automatic implementation of a Provider if you did

* for lazy binding
* if you need new instances on demand
* In general it is best practice to use a Provider for everything that has a state that might be changed. This way you will avoid undesired side effects. That is especially important for dependencies in objects that are shared between requests - for example a controller!
* In general, it is best practice using a Provider for everything that has a state that might be changed. This way you will avoid undesired side effects. That is especially important for dependencies in objects that are shared between requests - for example a controller!

*Example 1:*
This is the only code required to request a Provider as a dependency:
Expand Down Expand Up @@ -162,7 +162,7 @@ type service struct {
```

will essentially call `createSomething(new(SomethingElse))` everytime `SomethingProvider()` is called,
passing the resulting instance thru the injection to finalize uninjected fields.
passing the resulting instance through the injection to finalize uninjected fields.


### Optional injection
Expand All @@ -188,9 +188,9 @@ injector.Bind(new(Something))

### AnnotatedWith

By default a binding is unnamend, and thus requested with the `inject:""` tag.
By default a binding is unnamed, and thus requested with the `inject:""` tag.

However you can name bindings to have more concrete kinds of it. Using `AnnotatedWith` you can specify the name:
However, you can name bindings to have more concrete kinds of it. Using `AnnotatedWith` you can specify the name:

```go
injector.Bind((*Something)(nil)).AnnotatedWith("myAnnotation")
Expand Down Expand Up @@ -218,9 +218,9 @@ injector.Bind(new(Something)).To(MyType{})

If you want a factory to create your types then you rather use `ToProvider` instead of `To`.

`ToProvider` is a function which returns an instance (which again will go thru Dingo to fill dependencies).
`ToProvider` is a function which returns an instance (which again will go through Dingo to fill dependencies).

Also the provider can request arguments from Dingo which are necessary to construct the bounded type.
Also, the provider can request arguments from Dingo which are necessary to construct the bounded type.
If you need named arguments (e.g. a string instance annotated with a configuration value) you need to request
an instance of an object with these annotations, because Go does not allow to pass any meta-information on function
arguments.
Expand All @@ -244,7 +244,7 @@ then take the result of `*MyType` as the value for `Something`.

For situations where you have one, and only one, concrete instance you can use `ToInstance` to bind
something to the concrete instance. This is not the same as a Singleton!
(Even though the resuting behaviour is very similar.)
(Even though the resulting behaviour is very similar.)

```go
var myInstance = new(MyType)
Expand All @@ -267,7 +267,7 @@ If really necessary it is possible to use singletons

`In` allows us to bind in a scope, making the created instances scoped in a certain way.

Currently Dingo only allows to bind to `dingo.Singleton` and `dingo.ChildSingleton`.
Currently, Dingo only allows to bind to `dingo.Singleton` and `dingo.ChildSingleton`.

```go
injector.Bind(new(Something)).In(dingo.Singleton).To(MyType{})
Expand All @@ -287,7 +287,7 @@ the concrete creation to one goroutine via a scope+type specific Mutex which the
the Singleton and makes it available to other currently waiting injection requests, as
well as future injection requests.

By default it is advised to not use Singletons whenever possible, and rather use
By default, it is advised to not use Singletons whenever possible, and rather use
immutable objects you inject whenever you need them.

#### dingo.ChildSingleton
Expand Down Expand Up @@ -352,14 +352,14 @@ struct {
MultiBindings are used to allow multiple modules to register for a certain type, such as a list of
encoders, subscribers, etc.

Please not that MultiBindings are not always a clear pattern, as it might hide certain complexity.
Please note that MultiBindings are not always a clear pattern, as it might hide certain complexity.

Usually it is easier to request some kind of a registry in your module, and then register explicitly.
Usually it is easier to request some kind of registry in your module, and then register explicitly.


### Bind maps

Similiar to Multibindings, but with a key instead of a list
Similar to Multibindings, but with a key instead of a list
```go
MyService struct {
Ifaces map[string]Iface `inject:""`
Expand Down
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module flamingo.me/dingo

go 1.13
go 1.15

require (
github.com/client9/misspell v0.3.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/stretchr/testify v1.4.0
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f // indirect
github.com/gordonklaus/ineffassign v0.0.0-20210225214923-2e10b2664254 // indirect
github.com/stretchr/testify v1.7.0
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect
)
44 changes: 34 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,23 +1,47 @@
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gordonklaus/ineffassign v0.0.0-20210225214923-2e10b2664254 h1:Nb2aRlC404yz7gQIfRZxX9/MLvQiqXyiBTJtgAy6yrI=
github.com/gordonklaus/ineffassign v0.0.0-20210225214923-2e10b2664254/go.mod h1:M9mZEtGIsR1oDaZagNPNG9iq9n2HrhZ17dsXk73V3Lw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE=
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 h1:2M3HP5CCK1Si9FQhwnzYhXdG6DXeebvUHFpre8QvbyI=
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f h1:kDxGY2VmgABOe55qheT/TFqUMtcTHnomIPS1iv3G4Ms=
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7 h1:EBZoQjiKKPaLbPrbpssUfuHtwM6KV/vb4U85g/cigFY=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit 6df0d34

Please sign in to comment.