This repository has been archived by the owner on Apr 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support custom marshal and content type
- Loading branch information
Showing
6 changed files
with
1,510 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"time" | ||
|
||
"github.com/vicanso/elton" | ||
responder "github.com/vicanso/elton-responder" | ||
) | ||
|
||
type AutoGenerated struct { | ||
Users []struct { | ||
ID int `json:"id"` | ||
Username string `json:"username"` | ||
AvatarTemplate string `json:"avatar_template"` | ||
} `json:"users"` | ||
Topics struct { | ||
CanCreateTopic bool `json:"can_create_topic"` | ||
MoreTopicsURL string `json:"more_topics_url"` | ||
Draft interface{} `json:"draft"` | ||
DraftKey string `json:"draft_key"` | ||
DraftSequence interface{} `json:"draft_sequence"` | ||
PerPage int `json:"per_page"` | ||
Topics []struct { | ||
ID int `json:"id"` | ||
Title string `json:"title"` | ||
FancyTitle string `json:"fancy_title"` | ||
Slug string `json:"slug"` | ||
PostsCount int `json:"posts_count"` | ||
ReplyCount int `json:"reply_count"` | ||
HighestPostNumber int `json:"highest_post_number"` | ||
ImageURL string `json:"image_url"` | ||
CreatedAt time.Time `json:"created_at"` | ||
LastPostedAt time.Time `json:"last_posted_at"` | ||
Bumped bool `json:"bumped"` | ||
BumpedAt time.Time `json:"bumped_at"` | ||
Unseen bool `json:"unseen"` | ||
Pinned bool `json:"pinned"` | ||
Unpinned interface{} `json:"unpinned"` | ||
Excerpt string `json:"excerpt,omitempty"` | ||
Visible bool `json:"visible"` | ||
Closed bool `json:"closed"` | ||
Archived bool `json:"archived"` | ||
Bookmarked interface{} `json:"bookmarked"` | ||
Liked interface{} `json:"liked"` | ||
Views int `json:"views"` | ||
LikeCount int `json:"like_count"` | ||
HasSummary bool `json:"has_summary"` | ||
Archetype string `json:"archetype"` | ||
LastPosterUsername string `json:"last_poster_username"` | ||
CategoryID int `json:"category_id"` | ||
PinnedGlobally bool `json:"pinned_globally"` | ||
Posters []struct { | ||
Extras string `json:"extras"` | ||
Description string `json:"description"` | ||
UserID int `json:"user_id"` | ||
} `json:"posters"` | ||
} `json:"topics"` | ||
} `json:"topics"` | ||
} | ||
|
||
func main() { | ||
d := elton.New() | ||
|
||
buf, _ := ioutil.ReadFile("./test.json") | ||
genInfo := &AutoGenerated{} | ||
marshal := func(v interface{}) ([]byte, error) { | ||
return json.Marshal(v) | ||
} | ||
json.Unmarshal(buf, genInfo) | ||
|
||
d.Use(responder.New(responder.Config{ | ||
Marshal: marshal, | ||
})) | ||
d.GET("/", func(c *elton.Context) (err error) { | ||
c.Body = genInfo | ||
return | ||
}) | ||
|
||
d.ListenAndServe(":3000") | ||
} |
Oops, something went wrong.