mirror of
				https://github.com/nkanaev/yarr.git
				synced 2025-11-04 08:48:45 +00:00 
			
		
		
		
	item.status encoder/decoder
This commit is contained in:
		@@ -3,6 +3,7 @@ package storage
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"time"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type ItemStatus int
 | 
			
		||||
@@ -13,6 +14,31 @@ const (
 | 
			
		||||
	STARRED ItemStatus = 2
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var StatusRepresentations = map[ItemStatus]string {
 | 
			
		||||
	UNREAD: "unread",
 | 
			
		||||
	READ: "read",
 | 
			
		||||
	STARRED: "starred",
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var StatusValues = map[string]ItemStatus {
 | 
			
		||||
	"unread": UNREAD,
 | 
			
		||||
	"read": READ,
 | 
			
		||||
	"starred": STARRED,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s ItemStatus) MarshalJSON() ([]byte, error) {
 | 
			
		||||
	return json.Marshal(StatusRepresentations[s])
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *ItemStatus) UnmarshalJSON(b []byte) error {
 | 
			
		||||
	var str string
 | 
			
		||||
	if err := json.Unmarshal(b, &s); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	*s = StatusValues[str]
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Item struct {
 | 
			
		||||
	Id string `json:"id"`
 | 
			
		||||
	FeedId int64 `json:"feed_id"`
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user