8000 GitHub - nanozuki/akko: Generate go web APIs and swagger/OpenAPI documents.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

nanozuki/akko

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Akko

An annotation and code generation based web framework

Usage guide

First CRUD Example

  1. Just Write your actual logic function

    type Book struct {
        ID       int64    `json:"id"`
        Name     string   `json:"name"`
        AuthorID int64    `json:"author_id"`
        ISBN     string   `json:"ISBN"`
        Tags     []string `json:"tags"`
    }
    
    type BookPatch struct {
        Name   string
        Author int64
        ISBN   string
        NewTag string
    }
    
    type BookFilter struct {
        Tag   string `json:"tag"`
        Limit int    `json:"limit`
    }
    
    func (a *Applicaton) GetBookByID(ctx context.Context, id int64) (*Book, error)
    func (a *Applicaton) ListBooks(ctx context.Context, filter *BookFilter) ([]*Book, error)
    func (a *Applicaton) CreateBook(ctx context.Context, book *Book) (*Book, error)
    func (a *Applicaton) UpdateBook(ctx context.Context, id int64, patch *BookPatch) (*Book, error)
    func (a *Applicaton) DeleteBook(ctx context.Context, id int64) error
  2. add annotations to logic function

    // GetBookByID find a book by bookID, if book not exist, return NotFound error
    // [GET=/books/:id]
    func (a *Applicaton) GetBookByID(ctx context.Context, id int64) (*Book, error)
    // ListBooks get a list of books through filter, default limit is 10
    // [GET=/books query->filter]
    func (a *Applicaton) ListBooks(ctx context.Context, filter *BookFilter) ([]*Book, error)
    // Or you can define function like this
    // [GET=/books query->tag,limit]
    func (a *Applicaton) ListBooks(ctx context.Context, tag string, limit int) ([]*Book, error)
    // [POST=/books body.json->book]
    func (a *Applicaton) CreateBook(ctx context.Context, book *Book) (*Book, error)
    // [PUT=/books/:id body.json->patch, return.1.json->body]
    func (a *Applicaton) UpdateBook(ctx context.Context, id int64, patch *BookPatch) (*Book, error)
    // [DELETE=/books/:id]
    func (a *Applicaton) DeleteBook(ctx context.Context, id int64) error
  3. response

    Akko will try to find these three method for response and error:

    func (r Response) Status() int
    func (r Response) Body()   io.Reader
    func (r Response) Header() http.Header

    At default, will treat non-err response to json with 200 status code, and convert error to error string with 500.

About

Generate go web APIs and swagger/OpenAPI documents.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0