added demo file
This commit is contained in:
parent
66a9dd356f
commit
10933b856e
@ -2,7 +2,13 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package testdata
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
//go:generate jsonenums -type=ShirtSize
|
||||
type ShirtSize byte
|
||||
@ -28,3 +34,13 @@ const (
|
||||
Saturday
|
||||
Sunday
|
||||
)
|
||||
|
||||
func main() {
|
||||
v := struct {
|
||||
Size ShirtSize
|
||||
Day WeekDay
|
||||
}{M, Friday}
|
||||
if err := json.NewEncoder(os.Stdout).Encode(v); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// generated by jsonenums -type=ShirtSize; DO NOT EDIT
|
||||
|
||||
package testdata
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@ -63,7 +63,7 @@ func (r *ShirtSize) UnmarshalJSON(data []byte) error {
|
||||
*r = XL
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid ShirtSize %q", s)
|
||||
return fmt.Errorf("invalid ShirtSize %q", s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// generated by jsonenums -type=WeekDay; DO NOT EDIT
|
||||
|
||||
package testdata
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@ -69,7 +69,7 @@ func (r *WeekDay) UnmarshalJSON(data []byte) error {
|
||||
*r = Sunday
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid WeekDay %q", s)
|
||||
return fmt.Errorf("invalid WeekDay %q", s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user