refactor: create a type alias for error pages, so we can manage the msgpack encoding properly
This commit is contained in:
parent
f29c485b41
commit
96d99bb533
|
@ -14,8 +14,11 @@ var (
|
|||
_ Metadata = (*WebAppMetadata)(nil)
|
||||
_ SerializableMetadata = (*WebAppMetadata)(nil)
|
||||
_ SerializableMetadata = (*WebAppFileMap)(nil)
|
||||
_ SerializableMetadata = (*WebAppErrorPages)(nil)
|
||||
)
|
||||
|
||||
type WebAppErrorPages map[int]string
|
||||
|
||||
type WebAppMetadata struct {
|
||||
BaseMetadata
|
||||
Name string `json:"name"`
|
||||
|
@ -231,3 +234,48 @@ func (wafm *WebAppFileMap) DecodeMsgpack(decoder *msgpack.Decoder) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w WebAppErrorPages) EncodeMsgpack(enc *msgpack.Encoder) error {
|
||||
err := enc.EncodeMapLen(len(w))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for k, v := range w {
|
||||
err = enc.EncodeInt(int64(k))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = enc.EncodeString(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *WebAppErrorPages) DecodeMsgpack(dec *msgpack.Decoder) error {
|
||||
mapLen, err := dec.DecodeMapLen()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*w = make(map[int]string, mapLen)
|
||||
|
||||
for i := 0; i < mapLen; i++ {
|
||||
key, err := dec.DecodeInt()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
value, err := dec.DecodeString()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
(*w)[key] = value
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue