mirror of
https://github.com/Fishwaldo/huma.git
synced 2025-03-15 19:31:27 +00:00
docs: minor layout change for example code
This commit is contained in:
parent
393ebfedd8
commit
0b16d0eddb
2 changed files with 36 additions and 44 deletions
40
README.md
40
README.md
|
@ -93,22 +93,20 @@ func main() {
|
|||
})
|
||||
|
||||
notes := r.Resource("/notes")
|
||||
notes.List("Returns a list of all notes",
|
||||
func() []*NoteSummary {
|
||||
// Create a list of summaries from all the notes.
|
||||
summaries := make([]*NoteSummary, 0)
|
||||
notes.List("Returns a list of all notes", func() []*NoteSummary {
|
||||
// Create a list of summaries from all the notes.
|
||||
summaries := make([]*NoteSummary, 0)
|
||||
|
||||
memoryDB.Range(func(k, v interface{}) bool {
|
||||
summaries = append(summaries, &NoteSummary{
|
||||
ID: k.(string),
|
||||
Created: v.(*Note).Created,
|
||||
})
|
||||
return true
|
||||
memoryDB.Range(func(k, v interface{}) bool {
|
||||
summaries = append(summaries, &NoteSummary{
|
||||
ID: k.(string),
|
||||
Created: v.(*Note).Created,
|
||||
})
|
||||
return true
|
||||
})
|
||||
|
||||
return summaries
|
||||
},
|
||||
)
|
||||
return summaries
|
||||
})
|
||||
|
||||
// Add an `id` path parameter to create a note resource.
|
||||
note := notes.With(huma.PathParam("id", "Note ID", &huma.Schema{
|
||||
|
@ -117,16 +115,14 @@ func main() {
|
|||
|
||||
notFound := huma.ResponseError(http.StatusNotFound, "Note not found")
|
||||
|
||||
note.Put("Create or update a note",
|
||||
func(id string, n *Note) bool {
|
||||
// Set the created time to now and then save the note in the DB.
|
||||
n.Created = time.Now()
|
||||
memoryDB.Store(id, n)
|
||||
note.Put("Create or update a note", func(id string, n *Note) bool {
|
||||
// Set the created time to now and then save the note in the DB.
|
||||
n.Created = time.Now()
|
||||
memoryDB.Store(id, n)
|
||||
|
||||
// Empty responses don't have a body, so you can just return `true`.
|
||||
return true
|
||||
},
|
||||
)
|
||||
// Empty responses don't have a body, so you can just return `true`.
|
||||
return true
|
||||
})
|
||||
|
||||
note.With(notFound).Get("Get a note by its ID",
|
||||
func(id string) (*huma.ErrorModel, *Note) {
|
||||
|
|
|
@ -33,22 +33,20 @@ func main() {
|
|||
})
|
||||
|
||||
notes := r.Resource("/notes")
|
||||
notes.List("Returns a list of all notes",
|
||||
func() []*NoteSummary {
|
||||
// Create a list of summaries from all the notes.
|
||||
summaries := make([]*NoteSummary, 0)
|
||||
notes.List("Returns a list of all notes", func() []*NoteSummary {
|
||||
// Create a list of summaries from all the notes.
|
||||
summaries := make([]*NoteSummary, 0)
|
||||
|
||||
memoryDB.Range(func(k, v interface{}) bool {
|
||||
summaries = append(summaries, &NoteSummary{
|
||||
ID: k.(string),
|
||||
Created: v.(*Note).Created,
|
||||
})
|
||||
return true
|
||||
memoryDB.Range(func(k, v interface{}) bool {
|
||||
summaries = append(summaries, &NoteSummary{
|
||||
ID: k.(string),
|
||||
Created: v.(*Note).Created,
|
||||
})
|
||||
return true
|
||||
})
|
||||
|
||||
return summaries
|
||||
},
|
||||
)
|
||||
return summaries
|
||||
})
|
||||
|
||||
// Add an `id` path parameter to create a note resource.
|
||||
note := notes.With(huma.PathParam("id", "Note ID", &huma.Schema{
|
||||
|
@ -57,16 +55,14 @@ func main() {
|
|||
|
||||
notFound := huma.ResponseError(http.StatusNotFound, "Note not found")
|
||||
|
||||
note.Put("Create or update a note",
|
||||
func(id string, n *Note) bool {
|
||||
// Set the created time to now and then save the note in the DB.
|
||||
n.Created = time.Now()
|
||||
memoryDB.Store(id, n)
|
||||
note.Put("Create or update a note", func(id string, n *Note) bool {
|
||||
// Set the created time to now and then save the note in the DB.
|
||||
n.Created = time.Now()
|
||||
memoryDB.Store(id, n)
|
||||
|
||||
// Empty responses don't have a body, so you can just return `true`.
|
||||
return true
|
||||
},
|
||||
)
|
||||
// Empty responses don't have a body, so you can just return `true`.
|
||||
return true
|
||||
})
|
||||
|
||||
note.With(notFound).Get("Get a note by its ID",
|
||||
func(id string) (*huma.ErrorModel, *Note) {
|
||||
|
|
Loading…
Add table
Reference in a new issue