mirror of https://github.com/synctv-org/synctv
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
644 B
Go
41 lines
644 B
Go
1 year ago
|
package model
|
||
1 year ago
|
|
||
|
import (
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type ApiResp struct {
|
||
|
Time int64 `json:"time"`
|
||
|
Error string `json:"error,omitempty"`
|
||
|
Data any `json:"data,omitempty"`
|
||
|
}
|
||
|
|
||
|
func (ar *ApiResp) SetError(err error) {
|
||
|
ar.Error = err.Error()
|
||
|
}
|
||
|
|
||
|
func (ar *ApiResp) SetDate(data any) {
|
||
|
ar.Data = data
|
||
|
}
|
||
|
|
||
|
func NewApiErrorResp(err error) *ApiResp {
|
||
|
return &ApiResp{
|
||
|
Time: time.Now().UnixMicro(),
|
||
|
Error: err.Error(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func NewApiErrorStringResp(err string) *ApiResp {
|
||
|
return &ApiResp{
|
||
|
Time: time.Now().UnixMicro(),
|
||
|
Error: err,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func NewApiDataResp(data any) *ApiResp {
|
||
|
return &ApiResp{
|
||
|
Time: time.Now().UnixMicro(),
|
||
|
Data: data,
|
||
|
}
|
||
|
}
|