Giter Site home page Giter Site logo

genny's People

Contributors

bits01 avatar crevil avatar dimchansky avatar ghostsquad avatar hneemann avatar itsmontoya avatar justnoise avatar martinlindhe avatar matryer avatar pdrum avatar tylerb avatar westonplatter avatar zwcn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

genny's Issues

Some imports being lost on generation

It appears than non-built-in import statements are being lost on generation. As an example, take a "simpletest.go" file that looks like this:

package test

import (
        "fmt"
        "github.com/gorilla/mux"
        "github.com/cheekybits/genny/generic"
)

type MyType generic.Type

func MyTypeFunction() {
        _ := mux.NewRouter()
        fmt.Println("Hello")
}

if I then run the command cat simpletest.go | genny gen "MyType=ConcreteType" > simpletest_gen.go I get the following output:

// This file was automatically generated by genny.
// Any changes will be lost if this file is regenerated.
// see https://github.com/cheekybits/genny

package test

import "fmt"

func ConcreteTypeFunction() {
    _ := mux.NewRouter()
    fmt.Println("Hello")
}

You can see the import statement has correctly dropped the genny reference, but also incorrectly removed the mux reference which means the code is now invalid.

Am I doing something wrong?

Check if specific type name has a valid syntax

Hi!

Looks like I misunderstood the concepts of genny and passed a specific type with a package name as genny arguments. The problem is that an error message is not pointed to the cause directly it's not trivial to debug. Actually, I resorted to binary search to figure it out.

Code:

//go:generate genny -pkg=test -in=../templates/main.go -out=main.go gen "MyType=package.SpecificType"

Error:

Failed to goimports the generated code: ../templates/main.go:10:12: expected type, found '.' (and 1 more errors)
main.go:3: running "genny": exit status 4

Not all instances of the argument type getting rewritten

So, I decided to take a look at genny, just poking around, implementing a pretty dumb digraph...

package digraph

import "github.com/cheekybits/genny/generic"

type Node generic.Type

type DigraphNode struct {
    nodes map[Node][]Node
}

func NewDigraphNode() *DigraphNode {
    return &DigraphNode{
        nodes: make(map[Node][]Node),
    }
}

func (dig *DigraphNode) Add(n Node) {
    if _, exists := dig.nodes[n]; exists {
        return
    }

    dig.nodes[n] = nil
}

func (dig *DigraphNode) Connect(a, b Node) {
    dig.Add(a)
    dig.Add(b)

    dig.nodes[a] = append(dig.nodes[a], b)
}

But when I run

$ cat generic.go | genny gen Node=int

I get

// This file was automatically generated by genny.
// Any changes will be lost if this file is regenerated.
// see https://github.com/cheekybits/genny

package digraph

type DigraphInt struct {
    nodes map[int][]Node
}

func NewDigraphInt() *DigraphInt {
    return &DigraphInt{
        nodes: make(map[int][]Node),
    }
}

func (dig *DigraphInt) Add(n int) {
    if _, exists := dig.nodes[n]; exists {
        return
    }

    dig.nodes[n] = nil
}

func (dig *DigraphInt) Connect(a, b int) {
    dig.Add(a)
    dig.Add(b)

    dig.nodes[a] = append(dig.nodes[a], b)
}

As you can see, not all instances of the Node type in the code got rewritten.

How do I... basetypes?

Hey. I'm having good success with genny but now I have a spazzy-issues.

Code:

func (arr *T) pop () BASETYPE { l := len(*arr)-1; val := (*arr)[l]; *arr = (*arr)[:l]; return val }

Question

One. is there any way to automatically deduce BASETYPE to int from T being []int?
I tried:

func (arr *TSlice) pop () T { l := len(*arr)-1; val := (*arr)[l]; *arr = (*arr)[:l]; return val }

but after running go generate Tslice is named "intSlice" so I cannot export it, which is my next question:
Two. I'm exporting my package so custom types have to be Uppercased, so the way I was building slices is no longer work. any suggestions on how to get "intSlice" to "IntSlice" if i generate with "int"? (so I can use it as as the base type)

edit: NVM I should just use a second var. I'm still kind of curious as to the 2nd question, or if theres a basetype() API for genny though. Cheers and thanks for the software, most simple generator I've seen for Go.

Are slices supported?

This is what I'm trying to do, works fine for simple types, but fails with slices:

package providers

import (
	"github.com/cheekybits/genny/generic"
)

//go:generate genny -in=$GOFILE -out=gen_$GOFILE gen "T=[]string"

type T generic.Type

type TProvider interface {
	Get() (T, error)
}

thanks

Invalid code generated

If I have something like the following and replace X with int

type _X_ generic.Type

type Cell_X_ struct {
    Value int
}

func m(_X_) {}

func example() {
    a := Cell_X_{}
    m(Cell_X_{})
}

The following code which wont compile is generated.

type CellInt struct {
    Value int
}

func m(int) {}

func example() {
    a := CellInt{}
    m(Cellint{})
}

Is this a limitation in how genny works or a bug?

define more type separately in 1 go file

check code below , I just want to define 2 type separately in 1 file
however it generate ReadPairInt8 ReadPairInt16 many times,
could u find a way fix it, like if there is only 1 type in one function , do not repeat it
or define a generic.SingleType
`
//go:generate genny -in=$GOFILE -out=../util/$GOFILE gen "T1=int8,int16,int32,int64,int,uint8,uint16,uint32,uint64,uint T2=float32,float64"

package util

import (
"strconv"
"github.com/cheekybits/genny/generic"
)

type T1 generic.Type

func ReadPairT1(data string) (x, y T1) {
splits := SplitParams(data)
lx, _ := strconv.Atoi(splits[0])
ly, _ := strconv.Atoi(splits[1])
x = T1(lx)
y = T1(ly)
return
}

type T2 generic.Type

func ReadPairT2(data string) (x, y T2) {
splits := SplitParams(data)
lx, _ := strconv.ParseFloat(splits[0], 32)
ly, _ := strconv.ParseFloat(splits[1], 32)
x = T2(lx)
y = T2(ly)
return
}
`

Allow generation of exported and non exported types from the same generic code.

It would be nice to not pollute a package's namespace with exported types that are not useable from outside of the package due to the use of internal types for the generic types. One way to do this is to add a 'private' flag to the parse.Generics function and to switch from specificLg to specificSm in subIntoLiteral if this flag is set.

genny leaves around an empty file on failure.

if genny fails to generate a code due to not being able to locate the file.
it still generates a empty file leading to subsequent calls to fail with the follow error
btree.gen.go:1:1: expected 'package', found 'EOF'

should probably not create the file until we are ready to write its contents.

Generates specific type with lower case when it should be capitalized

The code generated by genny generates the object name (ObjInt) with the specific type in
lower case when it should be capitalized. This occurs when the object name is the
parameter of new function. Does not occur if preceded by a space:

package dsp

import "github.com/cheekybits/genny/generic"

//go:generate genny -in=$GOFILE -out=gen-$GOFILE gen "NumberType=int"

type NumberType generic.Number

type ObjNumberType struct {
	v NumberType
}

func NewNumberType() *ObjNumberType {

	// Works
	//return &{ObjNumberType}

	// Works (there is a space preceding the object name)
	//return new( ObjNumberType)

	// Does not work -> n := new(Objint) (Lowercase Int)
	n := new(ObjNumberType)
	return n
}

wordify breaks calls to APIs made while generating

Eg

type GenericType generic.Type

type NameGenericType Interface {
    DoSomthingGenericType()
}

func Stuff(ngt NameGenericType) {
   ngt.DoSomthingGenericType()
}

When generating with uint8 produces

type uint8 interface {
	DoSomthingUint8()
}

func Stuff(ngt uint8) {
	ngt.DoSomthinguint8()
}

Please create a new tag for the latest master branch

Using go install to install genny will not include the change in the latest master branch, namely the -tag flag features. Is it possible to create a new tag for the latest commit? I believe the -tag will be helpful in many use cases.

Collect generics into composed interface

I would like

//go:generate genny -in=$GOFILE -out=$GOFILE_gen gen "Datatype=string,int"

type Datatype generic.Type
type GetterDatatype interface {
  GetDataType(column string) (DataType, err)
}
type HasGetters interface {
  GetterDatatype
} 

To expand into

type GetterInt interface {
  GetInt(column string) (int, err)
}
type GetterString interface {
  GetString(column string) (string, err)
}
type HasGetters interface {
  GetterInt
  GetterString
}

But, of course, it doesn't. Is this a worthy enhancement? Is there a workaround to define HasGetters (other than knowing ahead of time what the datatypes are)?

Error while using genny command

Input

package trie

import "github.com/cheekybits/genny/generic"

type ValueType generic.Type

//Node represents a node in the trie
type Node struct {
	branches [256]*Node
	val      generic.Type
	terminal bool
}

// Walk returns the node reached along edge c, if one exists. If node doesn't
// exist we return nil
func (n *Node) Walk(c byte) *Node {
	return n.branches[c]
}

// Terminal indicates whether n is terminal in the trie (that is, whether the path from the root to n
// represents an element in the set). For instance, if the root node is terminal, then []byte{} is in the
// trie.
func (n *Node) Terminal() bool { return n.terminal }

// Val gives the value associated with this node. It panics if n is not terminal.
func (n *Node) Val() generic.Type {
	if !n.terminal {
		panic("Val called on non-terminal node")
	}
	return n.val
}

Generation command

 genny -in node.go gen "ValueType=int"

Error

Failed to goimports the generated code: node.go:28:2: expected declaration, found 'if'

Separate generated code in multiple files

Could genny offer a command line option to separate generated code in multiple files?

For example, "SomeType=string,int" will generate gen-source-string.go and gen-source-int.go.

Switch to a standard codegen comment marker

I was looking at the go generics options available today and noticed in the docs that this project seems to be using a header of:

// This file was automatically generated by genny.
// Any changes will be lost if this file is regenerated.
// see https://github.com/cheekybits/genny

As it were, this header format isn't usually recognized as machine-generated by common linters.

Would it be possible to switch to the community standard header format? Perhaps something like this:

// Code generated by genny - DO NOT EDIT.
// https://github.com/cheekybits/genny

This change would make it such that any linters could recognize that the code isn't human-edited/maintained, and automatically make the appropriate "ignore issues in this file" determination.

Thanks for writing up this tooling, and I hope you're having a fantastic day! :)

genny get

This works:

wget -q -O - "https://github.com/metabition/gennylib/raw/master/maps/concurrentmap.go" | genny gen "KeyType=BUILTINS ValueType=BUILTINS"

Would be much simpler if it could be this:

genny -out="outfile.go" get maps/concurrentmap "KeyType=BUILTINS ValueType=BUILTINS"

Also validate that go generate works:

//go:generate genny -out="outfile.go" get maps/concurrentmap "KeyType=BUILTINS ValueType=BUILTINS"

Remove `// +build ignore` tags from generated output

To prevent a template file from being included in the build process a build tag can be added at the top:

// +build ignore

package foo

Unfortunately, these aren't removed from the generated output. As a result the generated code is also not included in the build.

TestCustomTypesMap test fails on some systems

I found go test TestCustomTypesMap fails on Debian build farm: alpha powerpc ppc64 x32.

As a tentative workaround, I'll set to ignore this failure for the next upload to Debian.
Please kindly check whether this can be fixed. Thank you!

error log:

=== RUN   TestCustomTypesMap
    generic_simplemap_test.go:32: 
        	Error Trace:	generic_simplemap_test.go:32
        	Error:      	Should be false
        	Test:       	TestCustomTypesMap
--- FAIL: TestCustomTypesMap (0.00s)

running "genny": exec: "genny": executable file not found in $PATH

//go:generate genny -in=$GOFILE -out=gen-$GOFILE gen "KeyType=string,int ValueType=string,int"

go generate ./... command with above comment reproduce
running "genny": exec: "genny": executable file not found in $PATH messege for me.

However, if I do that command with
//go:generate $GOPATH/bin/genny -in=$GOFILE -out=gen-$GOFILE gen "KeyType=string,int ValueType=string,int"
this comment, genny generation works for me well.

I want to use //go:generate genny -in=$GOFILE -out=gen-$GOFILE gen "KeyType=string,int ValueType=string,int" this comment which is document's recommended comment.

How can I use this one with the best?

below is my go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jayden/Library/Caches/go-build"
GOENV="/Users/jayden/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/jayden/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/jayden/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/jayden/Desktop/vitalcare-backend/go/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/sn/k8tknb_14qdb9nwxb6qd7cv80000gn/T/go-build483121234=/tmp/go-build -gno-record-gcc-switches -fno-common

Thanks!

Remove comment for generic.Type

If users write a comment above generic.Type (as per golint), we should remove it when generating specific code to avoid orphan comments.

Imports not generated correctly

In my template I have these imports:

import (
"errors"
"fmt"
"strings"

"github.com/deoxxa/gojson"
"github.com/macropodhq/go.uuid"
"github.com/foo/bar/entities"
"github.com/foo/bar/fdb"
"github.com/foo/bar/security"
"github.com/foo/simplelog"
)

My generated files have imports looking like this:

import (
"encoding/json"
"strings"

"github.com/facebookgo/stackerr"
uuid "github.com/macropodhq/go.uuid"
"github.com/foo/bar/entities"
"github.com/foo/bar/fdb"
"github.com/foo/bar/security"
"github.com/foo/simplelog"
)

You can see that "errors" has been removed (thus preventing my code from compiling), and "github.com/macropodhq/go.uuid" has been renamed to "uuid" (I didn't ask for it, but OK). Furthermore it has decided to replace the custom json package we use with the standard "Go encoding/json" package. I guess genny is auto-fixing the imports section - but it's doing it wrongly.

Add generic Integer type

I encounter an error when using a generic type to index a slice or as the len argument to make

non-integer len argument in make([]IntType) - IntType
non-integer slice index n

My workaround has been to add a generic.Integer type, in addition to the existing generic.Number type. An alternative might be to change the generic.Number definition to:

type Number int

Another alternative is to add a // +build ignore tag to the template file, but then I think it can't be used for generic testing.

code cleanup in parse.go drops all import statements and is potentially buggy in other infrequent scenarios

Here is a fun issue:

  • I import context, errors, and github.com/go-resty/resty in a fairly complicated source file inside a pre-modules monorepo setup that has to do fun things to GOPATH to work.
  • The code in parse.go for cleaning up the output here drops all import statements.
  • The invocation of golang.org/x/tools/imports apparently tries to work out what you need to import in order to automatically add it code
  • But the import statements are missing, so it has nothing to go off of, and it's only able to work out context and github.com/go-resty/resty, dropping errors and causing code to not compile.

My temporary fix is to fork Genny in order to remove the continue statements used to skip import statements. This can't work on multiple generated types in the same invocation, but I'm generating one type per file for a REST client for our internal microservices, so it lets me make progress.

Having the import statements does fix it.

I think that golang.org/x/tools/imports adding imports back in hid the issue. The first thing i tried to do before I dug in far enough to figure out what is actually going on was make a test case. I couldn't cause this to fail in an isolated setting. I think that mostly it's smart enough to magically work out what it needs to do just enough that dropping all import statements can work in most cases.

I can't share the monorepo or the code, and since I can't get a standalone test case working I'm not sure how to let someone else reproduce it. If necessary, I may be able to get permission to share the specific file being used as input, since it contains no code specific to our setup. Dropping all import statements can be seen by modifying the Generics function in parse.go to return just before invocation of golang.org/x/tools/imports.

Since the way Genny works means that we can't have variation in the import statements themselves based off the type parameters (or, at least as far as I know it doesn't), I think the fix here is to refactor the code cleanup to run per typeset rather than on the entire concatenated output. Flags can then be passed to the first one telling it that it's the first one, so that it knows not to drop package and import statements, then unconditionally drop from all the others.

Furthermore, it looks like there's some other oddities that probably should be handled in the same refactor, as I think they can be solved in a similar way:

  • code cleanup isn't robust against whitespace. I'm not sure who would indent their package and import statements, but it's possible and it looks like this code isn't going to recognize them because it doesn't strip lines before checking their prefix.
  • It might also not be robust against variables named like packageContainer (i.e. packageContainer := NewPackageContainer()). Currently I think that gets through because such code is frequently indented.
  • It looks like the import case is relatively robust as long as it's a block. Most import statements are, but it's possible to just have import "foo" and I don't think this code handles that either.

If refactored to run code cleanup once per typeset, it's guaranteed to be package, imports, code in that order possibly with comments, which should handle the latter points and make it safe to strip whitespace. Specifically, I believe ignoring everything until a non-comment non-package non-import line is encountered and then just including everything as-is after that point will do it.

I'll try to find the time to refactor if I'm headed in the right direction, but it might be better if someone who is familiar with the internals does it, plus I haven't got a lot of time on my hands so it might be a while. If anyone can at least let me know if this all seems right before I put the time in to refactor, I'd appreciate it.

genny imports.Parse usage drops aliased imports

Problem

If your genny templates include renamed imports they'll be incorrectly removed from the output. Initially I thought this was a bug in imports.Parse but when running goimports (which I believe uses the imports lib as it's backend) i don't see the same behavior.

I think what's going on is that because genny passes the generated code into imports.Parse without any imports included the renamed packages aren't able to resolve.

Repro case genny-test

Possible solution

  1. Add -trustImports which will bypass the import processing from imports; I've made this modification locally and it works well enough. Two issues with it a) you lose the implicit formatting that imports does for you b) it doesn't remove the generic import that you pick up from your template. I'm side stepped (b) by not compiling my templates and just leaving the generic import out.
  2. Don't strip imports from the cleaned output that gets passed into imports.Process. I think this should let imports do its thing without genny intervention.

I know 1 works, I didn't bother trying 2 as I found a suitable work around for my case.

Work around

Since 1 & 2 both require library changes some work arounds for anyone else that may hit this

  1. Just stop renaming! If that's not possible...
  2. declare your package imported as the name you're trying to use (i.e. package $name differs from directory); this may necessitate changes in other places the package is imported but often works...
  3. add a non-generated file that references the things you need access to within the imported package (in limited cases this is sufficient).
  4. and, lest we forget, fork genny and implement solution 1 or 2 (and provide a PR ๐Ÿ˜€)

import stmt removed in output (sometimes)

I have some imports like:

import (
	"fmt"
	"environment/types"
	"environment/utils"
)

But those stmt disappeared from output (sometimes) even if the semantics of my code is completely vaild

Make the generated header comment customisable

The current header (below) is hardcoded. This needs to be made customisable so that we can give more specific information on how the code is generated in each specific instance (could be through Makefile, through documented process, through go generate, ...).

header:

// This file was automatically generated by genny.
// Any changes will be lost if this file is regenerated.
// see https://github.com/cheekybits/genny

genny can not support slice type

//go:generate genny -pkg chr -in=../gen/grow.go -out=chargrow.go gen "SliceType=float32,float64,[]int"

package gen

import (
"github.com/cheekybits/genny/generic"
)

func GrowSliceType(sli *[]SliceType, n int) {
dif := n - cap(*sli)
if dif > 0 {
*sli = append((*sli)[:cap(*sli)], make([]SliceType, dif)...)
} else {
*sli = (*sli)[:n]
}
}

error
Failed to goimports the generated code: ../gen/grow.go:36:10: expected '(', found '['
char.go:1: running "genny": exit status 4

Any way to keep //go:generate?

Like the title suggests, I think it would be nice to keep the thing. Both as (human, not computer) memory, and in case you need to change something later.

Lowercase replace in strings?

template

package xmpl

import (
	"github.com/jmoiron/sqlx"
)

type Types []Type

func GetTypes(db *sqlx.DB) (Types, error) {
	result := Types{}
	err := db.Select(&result, "SELECT * FROM table;")
	return result, err
}

generated with

//go:generate genny -in=$GOFILE -out=gen-$GOFILE gen "Type=Operation table=operation"

will replace table by Operation, but not operation:

// This file was automatically generated by genny.
// Any changes will be lost if this file is regenerated.
// see https://github.com/cheekybits/genny

package operation

import "github.com/jmoiron/sqlx"

type Operations []Operation

func GetOperations(db *sqlx.DB) (Operations, error) {
	result := Operations{}
	err := db.Select(&result, "SELECT * FROM Operation;")
	return result, err
}

support extending generic type

Hi.
Thank you for your providing a neat package!

I would like to extend generic type like this Java example so that I can call method in the
type.

public class Bar<T extends B & java.io.Serializable> {}

and I find I could do similar stuff with Genny. but it is a bit hacky way.

package genny

import "bytes"

// NOTE: this is how easy it is to define a generic type

//Something ..
type Something interface { //generic.Type
	String() string //generic.Type
} //generic.Type

// SomethingQueue is a queue of Somethings.
type SomethingQueue struct {
	items []Something
}

func NewSomethingQueue() *SomethingQueue {
	return &SomethingQueue{items: make([]Something, 0)}
}

func (q *SomethingQueue) Push(item Something) {
	q.items = append(q.items, item)
}

func (q *SomethingQueue) Pop() Something {
	item := q.items[0]
	q.items = q.items[1:]
	return item
}

func (q *SomethingQueue) String() string {
	var buf bytes.Buffer
	for _, item := range q.items {
		buf.WriteString(item.String())
	}
	return buf.String()
}

How about support this use case officially, and add "generic.ignore" for ignoring line?

Drops imports on github actions

reproducible project

genny-github-actions-issue

I am on windows 10 latest

vscode

The following works fine.

genny -in ./internal/genny/sarulabsdi/interface-types.go -out ./pkg/interface-types.go -pkg pkg gen "InterfaceType=IHello"
// This file was automatically generated by genny.
// Any changes will be lost if this file is regenerated.
// see https://github.com/cheekybits/genny

package pkg

import (
    "reflect"

    di "github.com/fluffy-bunny/sarulabsdi"
)

// ReflectTypeIHello used when your service claims to implement IHello
var ReflectTypeIHello = di.GetInterfaceReflectType((*IHello)(nil))

// AddIHelloByObj adds a prebuilt obj
func AddIHelloByObj(builder *di.Builder, obj interface{}) {
    di.AddSingletonWithImplementedTypesByObj(builder, obj, ReflectTypeIHello)
}

// AddSingletonIHello adds a type that implements IHello
func AddSingletonIHello(builder *di.Builder, implType reflect.Type) {
    di.AddSingletonWithImplementedTypes(builder, implType, ReflectTypeIHello)
}

Github actions issue

When I run the same command on github it produces the following output.

Where did the following go?

di "github.com/fluffy-bunny/sarulabsdi"
// This file was automatically generated by genny.
// Any changes will be lost if this file is regenerated.
// see https://github.com/cheekybits/genny

package pkg

import "reflect"

// ReflectTypeIHello used when your service claims to implement IHello
var ReflectTypeIHello = di.GetInterfaceReflectType((*IHello)(nil))

// AddIHelloByObj adds a prebuilt obj
func AddIHelloByObj(builder *di.Builder, obj interface{}) {
    di.AddSingletonWithImplementedTypesByObj(builder, obj, ReflectTypeIHello)
}

// AddSingletonIHello adds a type that implements IHello
func AddSingletonIHello(builder *di.Builder, implType reflect.Type) {
    di.AddSingletonWithImplementedTypes(builder, implType, ReflectTypeIHello)
}

So yea, its working on my machine but not on github actions. I am windows 10, github it ubuntu-latest.

generic.Type support function definition ?

i want to define function with generic.Type define. for example:
define template_demo.go :

  1. type ModelType generic.Type

func registerModelType() {
MngCreater = append(MngCreater, ModelType(GlobalmgDb))
}

  1. then run genny command:

input_file="./template_res_register.go"
out_file="res_register_1.go" ##
real_type="RegisterSignDailyFortuneMg,RegisterSecretChitchatWork" ###RegisterSecretChitchatWork
pkg_name="common_res"
genny -in ${input_file} -out ${out_file} -pkg ${pkg_name} gen "ModelType=${real_type}"

  1. then generated codes:

func registerRegisterSecretChitchatWork() {
MngCreater = append(MngCreater, RegisterSecretChitchatWork(GlobalmgDb))
}

  1. when i build project, error happen . show defined template file err:

cannot use ModelType(GlobalmgDb) (value of type ModelType) as data_cache.CreateRes value in argument to append: ModelType does not implement data_cache.CreateRes (missing method Create)

Flags usage not correct in README

The flags description in the Usage section of the README is showing the option name types instead of flags.

Actual

{types}  - (optional) Command line flags (see below)

Expected

{flags}  - (optional) Command line flags (see below)

-pkg doesn't appear to work

The help text and the readme seem to be implying that I can use -pkg to change the package statement at the top of the file, but this doesn't seem to work. I'm using the same template to generate a bunch of API clients for various microservices in different packages, and being able to name the microservice-specific subpackages for the microservices would be nice. At the moment I have to name them all client and alias.

If -pkg is supposed to do something else, then consider this a potential feature request. It's barely mentioned in the first place, so i'm not discounting me misunderstanding what it's for.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.