Rename http package to server

This commit is contained in:
2022-02-19 21:28:04 +00:00
parent 72b5bdde4f
commit daadfd45bc
13 changed files with 26 additions and 25 deletions

36
server/json-date.go Normal file
View File

@ -0,0 +1,36 @@
package server
import (
"encoding/json"
"fmt"
"strings"
"time"
)
type JSONDate time.Time
// Implement Marshaler and Unmarshaler interface
func (j *JSONDate) UnmarshalJSON(b []byte) error {
s := strings.Trim(string(b), "\"")
t, err := time.Parse("2006-01-02", s)
if err != nil {
return fmt.Errorf("parse date: %w", err)
}
*j = JSONDate(t)
return nil
}
func (j JSONDate) MarshalJSON() ([]byte, error) {
result, err := json.Marshal(time.Time(j))
if err != nil {
return nil, fmt.Errorf("marshal date: %w", err)
}
return result, nil
}
// Maybe a Format function for printing your date
func (j JSONDate) Format(s string) string {
t := time.Time(j)
return t.Format(s)
}