...

Source file src/github.com/go-chi/chi/_examples/versions/presenter/v2/article.go

Documentation: github.com/go-chi/chi/_examples/versions/presenter/v2

     1  package v2
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  
     7  	"github.com/go-chi/chi/_examples/versions/data"
     8  )
     9  
    10  // Article presented in API version 2.
    11  type Article struct {
    12  	// *v3.Article `json:",inline" xml:",inline"`
    13  
    14  	*data.Article
    15  
    16  	// Additional fields.
    17  	SelfURL string `json:"self_url" xml:"self_url"`
    18  
    19  	// Omitted fields.
    20  	URL interface{} `json:"url,omitempty" xml:"url,omitempty"`
    21  }
    22  
    23  func (a *Article) Render(w http.ResponseWriter, r *http.Request) error {
    24  	a.SelfURL = fmt.Sprintf("http://localhost:3333/v2?id=%v", a.ID)
    25  	return nil
    26  }
    27  
    28  func NewArticleResponse(article *data.Article) *Article {
    29  	return &Article{Article: article}
    30  }
    31  

View as plain text