Support package-names with dashes in them (#232)
Support package-names with dashes in them We were smart about aliasing if you have name-collisions, but not if your package name is something that's not a valid identifier, like `"path/to/my-package"`, which Go for better or worse allows. Now we remove all the invalid characters (in practice mainly dashes, dots, and leading digits). Fixes #231. Test plan: make check
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/Khan/genqlient/graphql"
|
||||
)
|
||||
|
||||
type ID string
|
||||
|
||||
type Pokemon struct {
|
||||
Species string `json:"species"`
|
||||
Level int `json:"level"`
|
||||
}
|
||||
|
||||
func (p Pokemon) Battle(q Pokemon) bool {
|
||||
return p.Level > q.Level
|
||||
}
|
||||
|
||||
type MyContext interface {
|
||||
context.Context
|
||||
|
||||
MyMethod()
|
||||
}
|
||||
|
||||
func GetClientFromNowhere() (graphql.Client, error) { return nil, nil }
|
||||
func GetClientFromContext(ctx context.Context) (graphql.Client, error) { return nil, nil }
|
||||
func GetClientFromMyContext(ctx MyContext) (graphql.Client, error) { return nil, nil }
|
||||
|
||||
const dateFormat = "2006-01-02"
|
||||
|
||||
func MarshalDate(t *time.Time) ([]byte, error) {
|
||||
// nil should never happen but we might as well check. zero-time does
|
||||
// happen because omitempty doesn't consider it zero; we'd prefer to write
|
||||
// null than "0001-01-01".
|
||||
//
|
||||
// (I mean, we're tests. Who cares! But we may as well try to match what
|
||||
// prod code would want.)
|
||||
if t == nil || t.IsZero() {
|
||||
return []byte("null"), nil
|
||||
}
|
||||
return []byte(`"` + t.Format(dateFormat) + `"`), nil
|
||||
}
|
||||
|
||||
func UnmarshalDate(b []byte, t *time.Time) error {
|
||||
// (modified from time.Time.UnmarshalJSON)
|
||||
var err error
|
||||
*t, err = time.Parse(`"`+dateFormat+`"`, string(b))
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user