feat: add HTTP migration bridges and extensible API binding
This commit is contained in:
29
examples/compatibility/ids/id.go
Normal file
29
examples/compatibility/ids/id.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// Package ids demonstrates an application-owned scalar. The framework does not
|
||||
// impose this ID policy on any other type or project.
|
||||
package ids
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ID int64
|
||||
|
||||
func (id ID) MarshalJSON() ([]byte, error) { return json.Marshal(strconv.FormatInt(int64(id), 10)) }
|
||||
func (id *ID) UnmarshalJSON(raw []byte) error {
|
||||
value := string(raw)
|
||||
if len(raw) > 0 && raw[0] == '"' {
|
||||
if err := json.Unmarshal(raw, &value); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return id.UnmarshalText([]byte(value))
|
||||
}
|
||||
func (id *ID) UnmarshalText(raw []byte) error {
|
||||
value, err := strconv.ParseInt(string(raw), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*id = ID(value)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user