Generate easyjson helpers for ghost data

pull/1/head
Nikita Tokarchuk 3 years ago
parent 78b82f5cc5
commit ea9d93443f
Signed by: mainnika
GPG Key ID: A595FB7E3E56911C
  1. 5
      frontend/ghost/data.go
  2. 2
      frontend/ghost/ghost.go
  3. 407
      frontend/ghost/ghost_easyjson.go

@ -3,12 +3,14 @@ package ghost
import "html/template"
// Pages are ghost pages data
//easyjson:json
type Pages struct {
Pages []Post `json:"pages"`
Meta Meta `json:"meta"`
}
// Post contains ghost post data
//easyjson:json
type Post struct {
ID string `json:"id"`
UUID string `json:"uuid"`
@ -18,11 +20,13 @@ type Post struct {
}
// Meta contains ghost result metadata
//easyjson:json
type Meta struct {
Pagination Pagination `json:"pagination"`
}
// Pagination contains ghost pagination data
//easyjson:json
type Pagination struct {
Page int `json:"page"`
Limit int `json:"limit"`
@ -31,6 +35,7 @@ type Pagination struct {
}
// Posts are ghost posts data
//easyjson:json
type Posts struct {
Posts []Post `json:"posts"`
Meta Meta `json:"meta"`

@ -1,5 +1,7 @@
package ghost
//go:generate $GOPATH/bin/easyjson -pkg -no_std_marshalers
// Client is the ghost backend client
type Client interface {
GetPosts(params ...QueryParam) (posts *Posts, err error)

@ -0,0 +1,407 @@
// Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT.
package ghost
import (
json "encoding/json"
easyjson "github.com/mailru/easyjson"
jlexer "github.com/mailru/easyjson/jlexer"
jwriter "github.com/mailru/easyjson/jwriter"
template "html/template"
)
// suppress unused package warning
var (
_ *json.RawMessage
_ *jlexer.Lexer
_ *jwriter.Writer
_ easyjson.Marshaler
)
func easyjson72852e1bDecodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost(in *jlexer.Lexer, out *Posts) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeFieldName(false)
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "posts":
if in.IsNull() {
in.Skip()
out.Posts = nil
} else {
in.Delim('[')
if out.Posts == nil {
if !in.IsDelim(']') {
out.Posts = make([]Post, 0, 0)
} else {
out.Posts = []Post{}
}
} else {
out.Posts = (out.Posts)[:0]
}
for !in.IsDelim(']') {
var v1 Post
(v1).UnmarshalEasyJSON(in)
out.Posts = append(out.Posts, v1)
in.WantComma()
}
in.Delim(']')
}
case "meta":
(out.Meta).UnmarshalEasyJSON(in)
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjson72852e1bEncodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost(out *jwriter.Writer, in Posts) {
out.RawByte('{')
first := true
_ = first
{
const prefix string = ",\"posts\":"
out.RawString(prefix[1:])
if in.Posts == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
out.RawString("null")
} else {
out.RawByte('[')
for v2, v3 := range in.Posts {
if v2 > 0 {
out.RawByte(',')
}
(v3).MarshalEasyJSON(out)
}
out.RawByte(']')
}
}
{
const prefix string = ",\"meta\":"
out.RawString(prefix)
(in.Meta).MarshalEasyJSON(out)
}
out.RawByte('}')
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v Posts) MarshalEasyJSON(w *jwriter.Writer) {
easyjson72852e1bEncodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost(w, v)
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *Posts) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson72852e1bDecodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost(l, v)
}
func easyjson72852e1bDecodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost1(in *jlexer.Lexer, out *Post) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeFieldName(false)
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "id":
out.ID = string(in.String())
case "uuid":
out.UUID = string(in.String())
case "title":
out.Title = string(in.String())
case "html":
out.HTML = template.HTML(in.String())
case "feature_image":
out.FImage = template.URL(in.String())
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjson72852e1bEncodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost1(out *jwriter.Writer, in Post) {
out.RawByte('{')
first := true
_ = first
{
const prefix string = ",\"id\":"
out.RawString(prefix[1:])
out.String(string(in.ID))
}
{
const prefix string = ",\"uuid\":"
out.RawString(prefix)
out.String(string(in.UUID))
}
{
const prefix string = ",\"title\":"
out.RawString(prefix)
out.String(string(in.Title))
}
{
const prefix string = ",\"html\":"
out.RawString(prefix)
out.String(string(in.HTML))
}
{
const prefix string = ",\"feature_image\":"
out.RawString(prefix)
out.String(string(in.FImage))
}
out.RawByte('}')
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v Post) MarshalEasyJSON(w *jwriter.Writer) {
easyjson72852e1bEncodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost1(w, v)
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *Post) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson72852e1bDecodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost1(l, v)
}
func easyjson72852e1bDecodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost2(in *jlexer.Lexer, out *Pagination) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeFieldName(false)
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "page":
out.Page = int(in.Int())
case "limit":
out.Limit = int(in.Int())
case "pages":
out.Pages = int(in.Int())
case "total":
out.Total = int(in.Int())
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjson72852e1bEncodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost2(out *jwriter.Writer, in Pagination) {
out.RawByte('{')
first := true
_ = first
{
const prefix string = ",\"page\":"
out.RawString(prefix[1:])
out.Int(int(in.Page))
}
{
const prefix string = ",\"limit\":"
out.RawString(prefix)
out.Int(int(in.Limit))
}
{
const prefix string = ",\"pages\":"
out.RawString(prefix)
out.Int(int(in.Pages))
}
{
const prefix string = ",\"total\":"
out.RawString(prefix)
out.Int(int(in.Total))
}
out.RawByte('}')
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v Pagination) MarshalEasyJSON(w *jwriter.Writer) {
easyjson72852e1bEncodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost2(w, v)
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *Pagination) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson72852e1bDecodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost2(l, v)
}
func easyjson72852e1bDecodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost3(in *jlexer.Lexer, out *Pages) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeFieldName(false)
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "pages":
if in.IsNull() {
in.Skip()
out.Pages = nil
} else {
in.Delim('[')
if out.Pages == nil {
if !in.IsDelim(']') {
out.Pages = make([]Post, 0, 0)
} else {
out.Pages = []Post{}
}
} else {
out.Pages = (out.Pages)[:0]
}
for !in.IsDelim(']') {
var v4 Post
(v4).UnmarshalEasyJSON(in)
out.Pages = append(out.Pages, v4)
in.WantComma()
}
in.Delim(']')
}
case "meta":
(out.Meta).UnmarshalEasyJSON(in)
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjson72852e1bEncodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost3(out *jwriter.Writer, in Pages) {
out.RawByte('{')
first := true
_ = first
{
const prefix string = ",\"pages\":"
out.RawString(prefix[1:])
if in.Pages == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 {
out.RawString("null")
} else {
out.RawByte('[')
for v5, v6 := range in.Pages {
if v5 > 0 {
out.RawByte(',')
}
(v6).MarshalEasyJSON(out)
}
out.RawByte(']')
}
}
{
const prefix string = ",\"meta\":"
out.RawString(prefix)
(in.Meta).MarshalEasyJSON(out)
}
out.RawByte('}')
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v Pages) MarshalEasyJSON(w *jwriter.Writer) {
easyjson72852e1bEncodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost3(w, v)
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *Pages) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson72852e1bDecodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost3(l, v)
}
func easyjson72852e1bDecodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost4(in *jlexer.Lexer, out *Meta) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeFieldName(false)
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "pagination":
(out.Pagination).UnmarshalEasyJSON(in)
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjson72852e1bEncodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost4(out *jwriter.Writer, in Meta) {
out.RawByte('{')
first := true
_ = first
{
const prefix string = ",\"pagination\":"
out.RawString(prefix[1:])
(in.Pagination).MarshalEasyJSON(out)
}
out.RawByte('}')
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v Meta) MarshalEasyJSON(w *jwriter.Writer) {
easyjson72852e1bEncodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost4(w, v)
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *Meta) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson72852e1bDecodeCodeTokarchUkMainnikaNikitaTokarchUkFrontendGhost4(l, v)
}
Loading…
Cancel
Save