Skip to content

Commit

Permalink
Merge pull request #12 from hidevopsio/dev-guide
Browse files Browse the repository at this point in the history
added dev guide
  • Loading branch information
john-deng authored Sep 21, 2018
2 parents d9a3c0d + 85d0bff commit c246060
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 14 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,42 @@ func (c *loginController) Post(request *userRequest) (response model.Response, e
}
```

## Development Guide

### Git workflow
Below, we outline one of the more common Git workflows that core developers use. Other Git workflows are also valid.

### Fork the main repository

* Go to https://github.com/hidevopsio/hiboot
* Click the "Fork" button (at the top right)

### Clone your fork

The commands below require that you have $GOPATH set ($GOPATH docs). We highly recommend you put Istio's code into your GOPATH. Note: the commands below will not work if there is more than one directory in your $GOPATH.

```bash
export GITHUB_USER=your-github-username
mkdir -p $GOPATH/src/github.com/hidevopsio
cd $GOPATH/src/github.com/hidevopsio
git clone https://github.com/$GITHUB_USER/hiboot
cd hiboot
git remote add upstream 'https://github.com/hidevopsio/hiboot'
git config --global --add http.followRedirects 1
```

### Create a branch and make changes

```bash
git checkout -b my-feature
# Then make your code changes
```

### Keeping your fork in sync

```bash
git fetch upstream
git rebase upstream/master
```

Note: If you have write access to the main repositories (e.g. github.com/hidevopsio/hiboot), you should modify your Git configuration so that you can't accidentally push to upstream:
19 changes: 11 additions & 8 deletions pkg/factory/autoconfigure/configfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,21 @@ func (f *ConfigurableFactory) InstantiateMethod(configuration interface{}, metho
argv[0] = reflect.ValueOf(configuration)
for a := 1; a < numIn; a++ {
// TODO: eliminate duplications
mt := method.Type.In(a)
iTyp := reflector.IndirectType(mt)
mtName := str.ToLowerCamel(iTyp.Name())
depInst := f.GetInstance(mtName)
mth := method.Type.In(a)
iTyp := reflector.IndirectType(mth)
mthName := str.ToLowerCamel(iTyp.Name())
depInst := f.GetInstance(mthName)
if depInst == nil {
pkgName := io.DirName(iTyp.PkgPath())
alternativeName := str.ToLowerCamel(pkgName) + iTyp.Name()
depInst = f.GetInstance(alternativeName)
}
if depInst == nil {
// TODO: check it it's dependency circle
depInst, err = f.InstantiateByName(configuration, strings.Title(mtName))
if depInst == nil {
// TODO: check it it's dependency circle
depInst, err = f.InstantiateByName(configuration, strings.Title(mthName))
if err != nil {
depInst, err = f.InstantiateByName(configuration, strings.Title(alternativeName))
}
}
}
if depInst == nil {
log.Errorf("[factory] failed to inject dependency as it can not be found")
Expand Down
51 changes: 47 additions & 4 deletions pkg/factory/autoconfigure/configfactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"os"
"path/filepath"
"testing"
"reflect"
)

type FakeProperties struct {
Expand All @@ -36,10 +37,6 @@ type FakeProperties struct {
Profile string `default:"${APP_PROFILES_ACTIVE:dev}"`
}

type FakeConfiguration struct {
app.Configuration
FakeProperties FakeProperties `mapstructure:"fake"`
}

type unknownConfiguration struct {
FakeProperties FakeProperties `mapstructure:"fake"`
Expand Down Expand Up @@ -119,6 +116,12 @@ func init() {
io.EnsureWorkDir(1, "config/application.yml")
}


type FakeConfiguration struct {
app.Configuration
FakeProperties FakeProperties `mapstructure:"fake"`
}

func (c *FakeConfiguration) Foo(bar *Bar) *Foo {
f := new(Foo)
f.Name = c.FakeProperties.Name
Expand All @@ -140,6 +143,35 @@ func (c *FakeConfiguration) Bar() *Bar {
return b
}


type EarthConfiguration struct {
app.Configuration
}

type Land struct {
Mountain *Mountain
}

type Tree struct {
}

type Mountain struct {
Tree *Tree
}

func (c *EarthConfiguration) Land(mountain *Mountain) *Land {
return &Land{Mountain: mountain}
}

func (c *EarthConfiguration) Mountain(tree *Tree) *Mountain {
return &Mountain{Tree: tree}
}


func (c *EarthConfiguration) AutoconfigureTestTree() *Tree {
return &Tree{}
}

func TestConfigurableFactory(t *testing.T) {
configPath := filepath.Join(os.TempDir(), "config")

Expand Down Expand Up @@ -229,6 +261,17 @@ func TestConfigurableFactory(t *testing.T) {
assert.NotEqual(t, nil, bb)
})


t.Run("should instantiate by name", func(t *testing.T) {
fc := new(EarthConfiguration)
objVal := reflect.ValueOf(fc)
method, ok := objVal.Type().MethodByName("Land")
assert.Equal(t, true, ok)
fb, err := f.InstantiateMethod(fc, method, "Land")
assert.Equal(t, nil, err)
assert.NotEqual(t, nil, fb)
})

t.Run("should get SystemConfiguration", func(t *testing.T) {
sysCfg := f.SystemConfiguration()
assert.NotEqual(t, nil, sysCfg)
Expand Down
4 changes: 2 additions & 2 deletions pkg/inject/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ const (
)

var (
// ErrNotImplemented: the interface is not implemented
// ErrNotImplemented the interface is not implemented
ErrNotImplemented = errors.New("[inject] interface is not implemented")

// ErrInvalidObject: the object is invalid
// ErrInvalidObject the object is invalid
ErrInvalidObject = errors.New("[inject] invalid object")

// ErrInvalidTagName the tag name is invalid
Expand Down
1 change: 1 addition & 0 deletions pkg/system/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package system

import "fmt"

// ErrInvalidController invalid controller
type ErrInvalidController struct {
Name string
}
Expand Down

0 comments on commit c246060

Please sign in to comment.