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
8 changes: 4 additions & 4 deletions examples/gomods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Steps

1. Go get enumer `go get -u github.com/dmarkham/enumer`
2. `go generate` This should create `pill_enumer.go`
3. `go run *.go` to see it in action
4. `go mod tidy` to remove the deps for `enumer` once your happy.
1. Go get enumer `go get -u github.com/igormiku/enumer`
2. `go generate` This should create `pill_enumer.go`
3. `go run *.go` to see it in action
4. `go mod tidy` to remove the deps for `enumer` once your happy.
2 changes: 1 addition & 1 deletion examples/gomods/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import "fmt"

//go:generate go run github.com/dmarkham/enumer -type=Pill -json
//go:generate go run github.com/igormiku/enumer -type=Pill -json
type Pill int

const (
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/dmarkham/enumer
module github.com/igormiku/enumer

require (
github.com/pascaldekloe/name v1.0.0
Expand Down
34 changes: 34 additions & 0 deletions sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,45 @@ const scanMethod = `func (i *%[1]s) Scan(value interface{}) error {
*i = val
return nil
}

`
const nullableImplementation = `
type Null%[1]s struct {
%[1]s %[1]s
Valid bool
}

func NewNull%[1]s(val interface{}) (x Null%[1]s) {
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
return
}

// Scan implements the Scanner interface.
func (x *Null%[1]s) Scan(value interface{}) (err error) {
if value == nil {
x.%[1]s, x.Valid = %[1]s(0), false
return
}

err = x.%[1]s.Scan(value)
x.Valid = (err == nil)
return
}

// Value implements the driver Valuer interface.
func (x Null%[1]s) Value() (driver.Value, error) {
if !x.Valid {
return nil, nil
}
return x.%[1]s.String(), nil
}
`

func (g *Generator) addValueAndScanMethod(typeName string) {
g.Printf("\n")
g.Printf(valueMethod, typeName)
g.Printf("\n\n")
g.Printf(scanMethod, typeName)
g.Printf("\n\n")
g.Printf(nullableImplementation, typeName)
}
4 changes: 2 additions & 2 deletions stringer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Enumer is a tool to generate Go code that adds useful methods to Go enums (constants with a specific type).
// It started as a fork of Rob Pike’s Stringer tool
//
// Please visit http://github.com/dmarkham/enumer for a comprehensive documentation
// Please visit http://github.com/igormiku/enumer for a comprehensive documentation
package main

import (
Expand Down Expand Up @@ -71,7 +71,7 @@ func Usage() {
_, _ = fmt.Fprintf(os.Stderr, "\tEnumer [flags] -type T [directory]\n")
_, _ = fmt.Fprintf(os.Stderr, "\tEnumer [flags] -type T files... # Must be a single package\n")
_, _ = fmt.Fprintf(os.Stderr, "For more information, see:\n")
_, _ = fmt.Fprintf(os.Stderr, "\thttp://godoc.org/github.com/dmarkham/enumer\n")
_, _ = fmt.Fprintf(os.Stderr, "\thttp://godoc.org/github.com/igormiku/enumer\n")
_, _ = fmt.Fprintf(os.Stderr, "Flags:\n")
flag.PrintDefaults()
}
Expand Down