Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions generator/template/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
const (
PackagePathGoKitEndpoint = "github.com/go-kit/kit/endpoint"
PackagePathContext = "context"
PackagePathGoKitLog = "github.com/go-kit/kit/log"
PackagePathGoKitLog = "github.com/go-kit/log"
PackagePathTime = "time"
PackagePathGoogleGRPC = "google.golang.org/grpc"
PackagePathGoogleGRPCStatus = "google.golang.org/grpc/status"
Expand All @@ -27,7 +27,7 @@ const (
PackagePathGoKitTransportHTTP = "github.com/go-kit/kit/transport/http"
PackagePathBytes = "bytes"
PackagePathJson = "encoding/json"
PackagePathIOUtil = "io/ioutil"
PackagePathIOUtil = "io"
PackagePathIO = "io"
PackagePathStrings = "strings"
PackagePathUrl = "net/url"
Expand Down Expand Up @@ -191,8 +191,7 @@ func nameOfLastResultError(fn *types.Function) string {

// Renders struct field.
//
// Visit *entity.Visit `json:"visit"`
//
// Visit *entity.Visit `json:"visit"`
func structField(ctx context.Context, field *types.Variable) *Statement {
s := structFieldName(field)
s.Add(fieldType(ctx, field.Type, false))
Expand All @@ -205,8 +204,7 @@ func structField(ctx context.Context, field *types.Variable) *Statement {

// Renders func params for definition.
//
// visit *entity.Visit, err error
//
// visit *entity.Visit, err error
func funcDefinitionParams(ctx context.Context, fields []types.Variable) *Statement {
c := &Statement{}
c.ListFunc(func(g *Group) {
Expand All @@ -219,8 +217,7 @@ func funcDefinitionParams(ctx context.Context, fields []types.Variable) *Stateme

// Renders field type for given func field.
//
// *repository.Visit
//
// *repository.Visit
func fieldType(ctx context.Context, field types.Type, allowEllipsis bool) *Statement {
c := &Statement{}
imported := false
Expand Down Expand Up @@ -277,9 +274,8 @@ func interfaceType(ctx context.Context, p *types.Interface) (code []Code) {

// Renders key/value pairs wrapped in Dict for provided fields.
//
// Err: err,
// Result: result,
//
// Err: err,
// Result: result,
func dictByVariables(fields []types.Variable) Dict {
return DictFunc(func(d Dict) {
for _, field := range fields {
Expand All @@ -290,8 +286,7 @@ func dictByVariables(fields []types.Variable) Dict {

// Render list of function receivers by signature.Result.
//
// Ans1, ans2, AnS3 -> ans1, ans2, anS3
//
// Ans1, ans2, AnS3 -> ans1, ans2, anS3
func paramNames(fields []types.Variable) *Statement {
var list []Code
for _, field := range fields {
Expand All @@ -306,8 +301,7 @@ func paramNames(fields []types.Variable) *Statement {

// Render full method definition with receiver, method name, args and results.
//
// func (e *Endpoints) Count(ctx context.Context, text string, symbol string) (count int)
//
// func (e *Endpoints) Count(ctx context.Context, text string, symbol string) (count int)
func methodDefinition(ctx context.Context, obj string, signature *types.Function) *Statement {
return Func().
Params(Id(rec(obj)). /*.Op("*")*/ Id(obj)).
Expand All @@ -322,8 +316,7 @@ func methodDefinitionFull(ctx context.Context, obj string, signature *types.Func

// Render full method definition with receiver, method name, args and results.
//
// func Count(ctx context.Context, text string, symbol string) (count int)
//
// func Count(ctx context.Context, text string, symbol string) (count int)
func functionDefinition(ctx context.Context, signature *types.Function) *Statement {
return Id(signature.Name).
Params(funcDefinitionParams(ctx, signature.Args)).
Expand Down
2 changes: 1 addition & 1 deletion generator/write_strategy/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s createFileStrategy) Write(renderer Renderer) error {
if err != nil {
return fmt.Errorf("unable to resolve path: %v", err)
}
dir := path.Dir(outpath)
dir := filepath.Dir(outpath)

_, err = os.Stat(dir)

Expand Down