diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/api/api.go | 63 | ||||
-rw-r--r-- | pkg/api/echo.go | 57 | ||||
-rw-r--r-- | pkg/api/list.go | 29 | ||||
-rw-r--r-- | pkg/api/message.go | 68 | ||||
-rw-r--r-- | pkg/api/misc.go | 15 | ||||
-rw-r--r-- | pkg/apiv1/api.go | 44 | ||||
-rw-r--r-- | pkg/apiv1/echo.go | 61 | ||||
-rw-r--r-- | pkg/apiv1/file.go (renamed from pkg/api/file.go) | 2 | ||||
-rw-r--r-- | pkg/apiv1/list.go | 32 | ||||
-rw-r--r-- | pkg/apiv1/message.go | 63 | ||||
-rw-r--r-- | pkg/apiv1/misc.go | 13 | ||||
-rw-r--r-- | pkg/apiv2/api.go | 27 | ||||
-rw-r--r-- | pkg/apiv2/echo.go | 36 | ||||
-rw-r--r-- | pkg/apiv2/message.go | 28 | ||||
-rw-r--r-- | pkg/fetcher/fetcher.go | 2 | ||||
-rw-r--r-- | pkg/idec/echo.go | 4 | ||||
-rw-r--r-- | pkg/idec/message.go | 89 | ||||
-rw-r--r-- | pkg/model/echo.go | 8 | ||||
-rw-r--r-- | pkg/model/file.go | 6 | ||||
-rw-r--r-- | pkg/model/message.go | 18 | ||||
-rw-r--r-- | pkg/model/point.go | 8 |
21 files changed, 410 insertions, 263 deletions
diff --git a/pkg/api/api.go b/pkg/api/api.go deleted file mode 100644 index fd55f1d..0000000 --- a/pkg/api/api.go +++ /dev/null @@ -1,63 +0,0 @@ -package api - -import ( - "context" - "log" - "net/http" - "os" - - "github.com/go-http-utils/logger" - - "gitrepo.ru/neonxp/idecnode/pkg/config" - "gitrepo.ru/neonxp/idecnode/pkg/idec" -) - -type API struct { - config *config.Config - idec *idec.IDEC -} - -func New(i *idec.IDEC, cfg *config.Config) *API { - return &API{ - config: cfg, - idec: i, - } -} - -func (a *API) Run(ctx context.Context) error { - errorLog := log.New(os.Stderr, "ERROR\t", log.Ldate|log.Ltime|log.Lshortfile) - - mux := http.NewServeMux() - - mux.HandleFunc(`GET /list.txt`, a.getListHandler) - mux.HandleFunc(`GET /blacklist.txt`, a.getBlacklistHandler) - mux.HandleFunc(`GET /u/e/{ids...}`, a.getEchosHandler) - mux.HandleFunc(`GET /u/m/{ids...}`, a.getBundleHandler) - mux.HandleFunc(`GET /u/point/{pauth}/{tmsg}`, a.postPointHandler) - mux.HandleFunc(`POST /u/point`, a.postPointHandler) - mux.HandleFunc(`GET /m/{msgID}`, a.getMessageHandler) - mux.HandleFunc(`GET /e/{id}`, a.getEchoHandler) - mux.HandleFunc(`GET /x/features`, a.getFeaturesHandler) - mux.HandleFunc(`GET /x/c/{ids...}`, a.getEchosInfo) - mux.HandleFunc(`POST /x/filelist`, a.getFilelistHandler) - mux.HandleFunc(`GET /x/filelist/{pauth}`, a.getFilelistHandler) - mux.HandleFunc(`POST /x/file`, a.getFileHandler) - mux.HandleFunc(`GET /x/file/{filename}`, a.getFileHandler) - - srv := http.Server{ - Addr: a.config.Listen, - Handler: logger.Handler(mux, os.Stdout, logger.Type(a.config.LoggerType)), - ErrorLog: errorLog, - } - - go func() { - <-ctx.Done() - srv.Close() - }() - log.Println("started IDEC node at", a.config.Listen) - if err := srv.ListenAndServe(); err != http.ErrServerClosed { - return err - } - - return nil -} diff --git a/pkg/api/echo.go b/pkg/api/echo.go deleted file mode 100644 index 8f7a852..0000000 --- a/pkg/api/echo.go +++ /dev/null @@ -1,57 +0,0 @@ -package api - -import ( - "fmt" - "net/http" - "strings" -) - -func (a *API) getEchoHandler(w http.ResponseWriter, r *http.Request) { - echoID := r.PathValue("id") - echos, err := a.idec.GetEchosByIDs([]string{echoID}, 0, 0) - if err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - - if len(echos) == 0 { - return - } - - fmt.Fprint(w, strings.Join(echos[echoID].Messages, "\n")) -} - -func (a *API) getEchosHandler(w http.ResponseWriter, r *http.Request) { - ids := strings.Split(r.PathValue("ids"), "/") - last := ids[len(ids)-1] - offset, limit := 0, 0 - if _, err := fmt.Sscanf(last, "%d:%d", &offset, &limit); err == nil { - ids = ids[:len(ids)-1] - } - echos, err := a.idec.GetEchosByIDs(ids, offset, limit) - if err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - - for _, echoID := range ids { - e := echos[echoID] - fmt.Fprintln(w, e.Name) - if len(e.Messages) > 0 { - fmt.Fprintln(w, strings.Join(e.Messages, "\n")) - } - } -} - -func (a *API) getEchosInfo(w http.ResponseWriter, r *http.Request) { - ids := strings.Split(r.PathValue("ids"), "/") - echos, err := a.idec.GetEchosByIDs(ids, 0, 0) - if err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - - for _, e := range echos { - fmt.Fprintf(w, "%s:%d\n", e.Name, e.Count) - } -} diff --git a/pkg/api/list.go b/pkg/api/list.go deleted file mode 100644 index 80a34ea..0000000 --- a/pkg/api/list.go +++ /dev/null @@ -1,29 +0,0 @@ -package api - -import ( - "fmt" - "net/http" - "strings" -) - -func (a *API) getListHandler(w http.ResponseWriter, r *http.Request) { - echos, err := a.idec.GetEchos() - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - for _, e := range echos { - fmt.Fprintf(w, "%s:%d:%s\n", e.Name, e.Count, e.Description) - } -} - -func (a *API) getBlacklistHandler(w http.ResponseWriter, r *http.Request) { - list, err := a.idec.GetBlacklist() - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - fmt.Fprint(w, strings.Join(list, "\n")) -} diff --git a/pkg/api/message.go b/pkg/api/message.go deleted file mode 100644 index 81e863f..0000000 --- a/pkg/api/message.go +++ /dev/null @@ -1,68 +0,0 @@ -package api - -import ( - "encoding/base64" - "fmt" - "log" - "net/http" - "strings" -) - -func (a *API) getBundleHandler(w http.ResponseWriter, r *http.Request) { - ids := strings.Split(r.PathValue("ids"), "/") - - for _, messageID := range ids { - msg, err := a.idec.GetMessage(messageID) - if err != nil { - log.Println("cant read file for message", messageID, err) - continue - } - - b64msg := base64.StdEncoding.EncodeToString([]byte(msg.Bundle())) - fmt.Fprintf(w, "%s:%s\n", messageID, b64msg) - } -} - -func (a *API) getMessageHandler(w http.ResponseWriter, r *http.Request) { - msgID := r.PathValue("msgID") - - msg, err := a.idec.GetMessage(msgID) - if err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - } - - _, err = fmt.Fprintln(w, msg.Bundle()) -} - -func (a *API) postPointHandler(w http.ResponseWriter, r *http.Request) { - msg, pauth := r.PathValue("tmsg"), r.PathValue("pauth") - if err := r.ParseForm(); err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - - form := r.PostForm - if form.Has("tmsg") { - msg = form.Get("tmsg") - } - if form.Has("pauth") { - pauth = form.Get("pauth") - } - - a.savePointMessage(w, msg, pauth) -} - -func (a *API) savePointMessage(w http.ResponseWriter, rawMessage, auth string) error { - point, err := a.idec.GetPointByAuth(auth) - if err != nil { - fmt.Fprintln(w, "error: no auth - wrong authstring") - return err - } - - if err := a.idec.SavePointMessage(point.Username, rawMessage); err != nil { - return err - } - fmt.Fprintln(w, "msg ok") - - return nil -} diff --git a/pkg/api/misc.go b/pkg/api/misc.go deleted file mode 100644 index 85f7a88..0000000 --- a/pkg/api/misc.go +++ /dev/null @@ -1,15 +0,0 @@ -package api - -import ( - "fmt" - "net/http" - "strings" - - "gitrepo.ru/neonxp/idecnode/pkg/idec" -) - -func (a *API) getFeaturesHandler(w http.ResponseWriter, r *http.Request) { - if _, err := fmt.Fprint(w, strings.Join(idec.Features, "\n")); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - } -} diff --git a/pkg/apiv1/api.go b/pkg/apiv1/api.go new file mode 100644 index 0000000..70e9cc1 --- /dev/null +++ b/pkg/apiv1/api.go @@ -0,0 +1,44 @@ +package apiv1 + +import ( + "github.com/labstack/echo/v4" + + "gitrepo.ru/neonxp/idecnode/pkg/config" + "gitrepo.ru/neonxp/idecnode/pkg/idec" +) + +type API struct { + config *config.Config + idec *idec.IDEC +} + +func New(i *idec.IDEC, cfg *config.Config) *API { + return &API{ + config: cfg, + idec: i, + } +} + +func (a *API) Register(e *echo.Echo) { + e.GET(`/list.txt`, a.getListHandler) + e.GET(`/blacklist.txt`, a.getBlacklistHandler) + + func(g *echo.Group) { + g.GET(`/e/*`, a.getEchosHandler) + g.GET(`/m/*`, a.getBundleHandler) + g.GET(`/point/:pauth/:tmsg`, a.postPointHandler) + g.POST(`/point`, a.postPointHandler) + }(e.Group("/u")) + + e.GET(`/e/:id`, a.getEchoHandler) + e.GET(`/m/:msgID`, a.getMessageHandler) + + func(g *echo.Group) { + e.GET(`/features`, a.getFeaturesHandler) + e.GET(`/c/*`, a.getEchosInfo) + // e.POST(`/filelist`, a.getFilelistHandler) + // e.GET(`/filelist/:pauth`, a.getFilelistHandler) + // e.POST(`/file`, a.getFileHandler) + // e.GET(`/file/:filename`, a.getFileHandler) + }(e.Group("/x")) +} diff --git a/pkg/apiv1/echo.go b/pkg/apiv1/echo.go new file mode 100644 index 0000000..68e7f48 --- /dev/null +++ b/pkg/apiv1/echo.go @@ -0,0 +1,61 @@ +package apiv1 + +import ( + "fmt" + "net/http" + "strings" + + "github.com/labstack/echo/v4" +) + +func (a *API) getEchoHandler(c echo.Context) error { + echoID := c.Param("id") + + echos, err := a.idec.GetEchosByIDs([]string{echoID}, 0, 0) + if err != nil { + return echo.ErrBadGateway + } + + if len(echos) == 0 { + return nil + } + + return c.String(http.StatusOK, strings.Join(echos[echoID].Messages, "\n")) +} + +func (a *API) getEchosHandler(c echo.Context) error { + ids := strings.Split(c.Param("*"), "/") + last := ids[len(ids)-1] + offset, limit := 0, 0 + if _, err := fmt.Sscanf(last, "%d:%d", &offset, &limit); err == nil { + ids = ids[:len(ids)-1] + } + echos, err := a.idec.GetEchosByIDs(ids, offset, limit) + if err != nil { + return echo.ErrBadRequest + } + + for _, echoID := range ids { + e := echos[echoID] + fmt.Fprintln(c.Response(), e.Name) + if len(e.Messages) > 0 { + fmt.Fprintln(c.Response(), strings.Join(e.Messages, "\n")) + } + } + + return nil +} + +func (a *API) getEchosInfo(c echo.Context) error { + ids := strings.Split(c.Param("*"), "/") + echos, err := a.idec.GetEchosByIDs(ids, 0, 0) + if err != nil { + return echo.ErrBadRequest + } + + for _, e := range echos { + fmt.Fprintf(c.Response(), "%s:%d\n", e.Name, e.Count) + } + + return nil +} diff --git a/pkg/api/file.go b/pkg/apiv1/file.go index e2fa8d9..eb1a8d8 100644 --- a/pkg/api/file.go +++ b/pkg/apiv1/file.go @@ -1,4 +1,4 @@ -package api +package apiv1 import ( "fmt" diff --git a/pkg/apiv1/list.go b/pkg/apiv1/list.go new file mode 100644 index 0000000..1e5dafc --- /dev/null +++ b/pkg/apiv1/list.go @@ -0,0 +1,32 @@ +package apiv1 + +import ( + "fmt" + "strings" + + "github.com/labstack/echo/v4" +) + +func (a *API) getListHandler(c echo.Context) error { + echos, err := a.idec.GetEchos() + if err != nil { + return echo.ErrInternalServerError + } + + for _, e := range echos { + fmt.Fprintf(c.Response(), "%s:%d:%s\n", e.Name, e.Count, e.Description) + } + + return nil +} + +func (a *API) getBlacklistHandler(c echo.Context) error { + list, err := a.idec.GetBlacklist() + if err != nil { + return echo.ErrInternalServerError + } + + fmt.Fprint(c.Response(), strings.Join(list, "\n")) + + return nil +} diff --git a/pkg/apiv1/message.go b/pkg/apiv1/message.go new file mode 100644 index 0000000..301b5cb --- /dev/null +++ b/pkg/apiv1/message.go @@ -0,0 +1,63 @@ +package apiv1 + +import ( + "encoding/base64" + "fmt" + "log" + "net/http" + "strings" + + "github.com/labstack/echo/v4" +) + +func (a *API) getBundleHandler(c echo.Context) error { + ids := strings.Split(c.Param("*"), "/") + + for _, messageID := range ids { + msg, err := a.idec.GetMessage(messageID) + if err != nil { + log.Println("cant read file for message", messageID, err) + continue + } + + b64msg := base64.StdEncoding.EncodeToString([]byte(msg.Bundle())) + fmt.Fprintf(c.Response(), "%s:%s\n", messageID, b64msg) + } + + return nil +} + +func (a *API) getMessageHandler(c echo.Context) error { + msgID := c.Param("msgID") + + msg, err := a.idec.GetMessage(msgID) + if err != nil { + return echo.ErrBadRequest + } + + return c.String(http.StatusOK, msg.Bundle()) +} + +func (a *API) postPointHandler(c echo.Context) error { + form := new(postForm) + + if err := c.Bind(form); err != nil { + return err + } + + point, err := a.idec.GetPointByAuth(form.PAuth) + if err != nil { + return c.String(http.StatusForbidden, "error: no auth - wrong authstring") + } + + if err := a.idec.SavePointMessage(point.Username, form.TMsg); err != nil { + return err + } + + return c.String(http.StatusOK, "msg ok") +} + +type postForm struct { + TMsg string `form:"tmsg"` + PAuth string `form:"pauth"` +} diff --git a/pkg/apiv1/misc.go b/pkg/apiv1/misc.go new file mode 100644 index 0000000..fa3ca21 --- /dev/null +++ b/pkg/apiv1/misc.go @@ -0,0 +1,13 @@ +package apiv1 + +import ( + "net/http" + "strings" + + "github.com/labstack/echo/v4" + "gitrepo.ru/neonxp/idecnode/pkg/idec" +) + +func (a *API) getFeaturesHandler(c echo.Context) error { + return c.String(http.StatusOK, strings.Join(idec.Features, "\n")) +} diff --git a/pkg/apiv2/api.go b/pkg/apiv2/api.go new file mode 100644 index 0000000..8fbd759 --- /dev/null +++ b/pkg/apiv2/api.go @@ -0,0 +1,27 @@ +package apiv2 + +import ( + "github.com/labstack/echo/v4" + "gitrepo.ru/neonxp/idecnode/pkg/config" + "gitrepo.ru/neonxp/idecnode/pkg/idec" +) + +type API struct { + config *config.Config + idec *idec.IDEC +} + +func New(i *idec.IDEC, cfg *config.Config) *API { + return &API{ + config: cfg, + idec: i, + } +} + +func (a *API) Register(e *echo.Echo) { + func(g *echo.Group) { + g.GET("/list", a.getListHandler) + g.GET("/e", a.getEchoHandler) + g.GET("/m", a.getMessagesHandler) + }(e.Group("/api")) +} diff --git a/pkg/apiv2/echo.go b/pkg/apiv2/echo.go new file mode 100644 index 0000000..daa68a8 --- /dev/null +++ b/pkg/apiv2/echo.go @@ -0,0 +1,36 @@ +package apiv2 + +import ( + "net/http" + + "github.com/labstack/echo/v4" +) + +func (a *API) getListHandler(c echo.Context) error { + echos, err := a.idec.GetEchos() + if err != nil { + return err + } + + return c.JSON(http.StatusOK, echos) +} + +func (a *API) getEchoHandler(c echo.Context) error { + q := new(getEchosRequest) + if err := c.Bind(q); err != nil { + return err + } + + echos, err := a.idec.GetEchosByIDs(q.EchoIDs, q.Offset, q.Limit) + if err != nil { + return err + } + + return c.JSON(http.StatusOK, echos) +} + +type getEchosRequest struct { + EchoIDs []string `query:"e"` + Offset int `query:"offset"` + Limit int `query:"limit"` +} diff --git a/pkg/apiv2/message.go b/pkg/apiv2/message.go new file mode 100644 index 0000000..7b06fde --- /dev/null +++ b/pkg/apiv2/message.go @@ -0,0 +1,28 @@ +package apiv2 + +import ( + "net/http" + + "github.com/labstack/echo/v4" +) + +func (a *API) getMessagesHandler(c echo.Context) error { + q := new(getMessagesRequest) + if err := c.Bind(q); err != nil { + return err + } + + msgs, err := a.idec.GetMessagesByEcho(q.Echo, q.Message, q.Offset, q.Limit) + if err != nil { + return err + } + + return c.JSON(http.StatusOK, msgs) +} + +type getMessagesRequest struct { + Echo string `query:"e"` + Message string `query:"m"` + Offset int `query:"offset"` + Limit int `query:"limit"` +} diff --git a/pkg/fetcher/fetcher.go b/pkg/fetcher/fetcher.go index 5083889..276b80b 100644 --- a/pkg/fetcher/fetcher.go +++ b/pkg/fetcher/fetcher.go @@ -67,7 +67,7 @@ func (f *Fetcher) downloadMessages(node config.Node, messagesToDownloads []strin func (f *Fetcher) getMissedEchoMessages(node config.Node, echoID string) ([]string, error) { missed := []string{} - messages, err := f.idec.GetMessagesByEcho(echoID, 0, 0) + messages, _, err := f.idec.GetMessageIDsByEcho(echoID, 0, 0) if err != nil { return nil, err } diff --git a/pkg/idec/echo.go b/pkg/idec/echo.go index db3cd70..04ed48c 100644 --- a/pkg/idec/echo.go +++ b/pkg/idec/echo.go @@ -18,7 +18,7 @@ func (i *IDEC) GetEchosByIDs(echoIDs []string, offset, limit int) (map[string]mo continue } - messages, err := i.GetMessagesByEcho(echoID, offset, limit) + messages, count, err := i.GetMessageIDsByEcho(echoID, offset, limit) if err != nil { return nil, err } @@ -27,7 +27,7 @@ func (i *IDEC) GetEchosByIDs(echoIDs []string, offset, limit int) (map[string]mo Name: echoID, Description: echoCfg.Description, Messages: messages, - Count: len(messages), + Count: count, } } diff --git a/pkg/idec/message.go b/pkg/idec/message.go index d018df2..48236e4 100644 --- a/pkg/idec/message.go +++ b/pkg/idec/message.go @@ -3,16 +3,17 @@ package idec import ( "encoding/base64" "fmt" + "log" "strings" "gitrepo.ru/neonxp/idecnode/pkg/model" "go.etcd.io/bbolt" ) -func (i *IDEC) GetMessagesByEcho(echoID string, offset, limit int) ([]string, error) { - messages := make([]string, 0) - - return messages, i.db.View(func(tx *bbolt.Tx) error { +func (i *IDEC) GetMessageIDsByEcho(echoID string, offset, limit int) ([]string, int, error) { + messages := make([]string, 0, limit) + count := 0 + return messages, count, i.db.View(func(tx *bbolt.Tx) error { if _, ok := i.config.Echos[echoID]; !ok { return nil } @@ -22,14 +23,15 @@ func (i *IDEC) GetMessagesByEcho(echoID string, offset, limit int) ([]string, er return nil } + count = bEcho.Stats().KeyN + cur := bEcho.Cursor() cur.First() - all := bEcho.Stats().KeyN if limit == 0 { - limit = all + limit = count } if offset < 0 { - offset = max(0, all+offset-1) + offset = max(0, count+offset-1) } for i := 0; i < offset; i++ { // skip offset entries @@ -47,6 +49,57 @@ func (i *IDEC) GetMessagesByEcho(echoID string, offset, limit int) ([]string, er }) } +func (i *IDEC) GetMessagesByEcho(echoID string, parent string, offset, limit int) ([]*model.Message, error) { + messages := make([]*model.Message, 0, limit) + return messages, i.db.View(func(tx *bbolt.Tx) error { + if _, ok := i.config.Echos[echoID]; !ok { + return nil + } + + bEcho := tx.Bucket([]byte(echoID)) + if bEcho == nil { + return nil + } + bMessages := tx.Bucket([]byte(msgBucket)) + if bMessages == nil { + return nil + } + + count := bEcho.Stats().KeyN + + cur := bEcho.Cursor() + cur.First() + if limit == 0 { + limit = count + } + if offset < 0 { + offset = max(0, count+offset-1) + } + for i := 0; i < offset; i++ { + // skip offset entries + cur.Next() + } + for i := 0; len(messages) < limit; i++ { + _, v := cur.Next() + if v == nil { + break + } + + msgText := bMessages.Get(v) + + msg, err := model.MessageFromBundle(string(v), string(msgText)) + if err != nil { + return err + } + if msg.RepTo == parent { + messages = append(messages, msg) + } + } + + return nil + }) +} + func (i *IDEC) GetMessage(messageID string) (*model.Message, error) { var msg *model.Message return msg, i.db.View(func(tx *bbolt.Tx) error { @@ -62,6 +115,28 @@ func (i *IDEC) GetMessage(messageID string) (*model.Message, error) { }) } +func (i *IDEC) GetMessages(messageIDs []string) ([]*model.Message, error) { + msgs := make([]*model.Message, 0, len(messageIDs)) + return msgs, i.db.View(func(tx *bbolt.Tx) error { + bucket := tx.Bucket([]byte(msgBucket)) + if bucket == nil { + return ErrMessageNotFound + } + for _, messageID := range messageIDs { + b := bucket.Get([]byte(messageID)) + msg, err := model.MessageFromBundle(messageID, string(b)) + if err != nil { + log.Println(err) + continue + } + + msgs = append(msgs, msg) + } + + return nil + }) +} + func (i *IDEC) SavePointMessage(point string, rawMessage string) error { rawMessage = strings.NewReplacer("-", "+", "_", "/").Replace(rawMessage) diff --git a/pkg/model/echo.go b/pkg/model/echo.go index 5f642da..21dcda6 100644 --- a/pkg/model/echo.go +++ b/pkg/model/echo.go @@ -6,10 +6,10 @@ import ( ) type Echo struct { - Name string - Description string - Count int - Messages []string + Name string `json:"name"` + Description string `json:"description"` + Count int `json:"count"` + Messages []string `json:"messages,omitempty"` } func (e *Echo) Format() string { diff --git a/pkg/model/file.go b/pkg/model/file.go index d87f581..b19461b 100644 --- a/pkg/model/file.go +++ b/pkg/model/file.go @@ -1,7 +1,7 @@ package model type File struct { - Name string - Size int64 - FullName string + Name string `json:"name"` + Size int64 `json:"size"` + FullName string `json:"full_name"` } diff --git a/pkg/model/message.go b/pkg/model/message.go index 3d15c46..3753419 100644 --- a/pkg/model/message.go +++ b/pkg/model/message.go @@ -8,15 +8,15 @@ import ( ) type Message struct { - ID string - RepTo string - EchoArea string - Date time.Time - From string - Addr string - MsgTo string - Subject string - Message string + ID string `json:"id"` + RepTo string `json:"rep_to"` + EchoArea string `json:"echo_area"` + Date time.Time `json:"date"` + From string `json:"from"` + Addr string `json:"addr"` + MsgTo string `json:"msg_to"` + Subject string `json:"subject"` + Message string `json:"message"` } func (m *Message) Bundle() string { diff --git a/pkg/model/point.go b/pkg/model/point.go index 02e9d43..3975ed9 100644 --- a/pkg/model/point.go +++ b/pkg/model/point.go @@ -7,8 +7,8 @@ func init() { } type Point struct { - Username string - Email string - Password []byte - AuthString string + Username string `json:"username"` + Email string `json:"email"` + Password []byte `json:"-"` + AuthString string `json:"auth_string"` } |