-
-
Notifications
You must be signed in to change notification settings - Fork 980
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update versions example to use latest render subpkg
- Loading branch information
Peter Kieltyka
authored and
Peter Kieltyka
committed
Mar 30, 2017
1 parent
2810210
commit 7f80c65
Showing
6 changed files
with
68 additions
and
131 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 |
---|---|---|
@@ -1,35 +1,22 @@ | ||
package v1 | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/pressly/chi/_examples/versions/presenter/v2" | ||
"github.com/pressly/chi/render" | ||
"github.com/pressly/chi/_examples/versions/data" | ||
) | ||
|
||
// Article presented in API version 1. | ||
type Article struct { | ||
*v2.Article `json:",inline" xml:",inline"` | ||
*data.Article | ||
|
||
Data map[string]bool `json:"data" xml:"data"` | ||
} | ||
|
||
var Presenter = render.NewPresenter(ArticleV2ToV1) | ||
|
||
func init() { | ||
Presenter.CopyFrom(v2.Presenter) | ||
func (a *Article) Render(w http.ResponseWriter, r *http.Request) error { | ||
return nil | ||
} | ||
|
||
func ArticleV2ToV1(r *http.Request, from *v2.Article) (*Article, error) { | ||
to := &Article{ | ||
Article: from, | ||
Data: map[string]bool{}, | ||
} | ||
to.SelfURL = fmt.Sprintf("http://localhost:3333/v1?id=%v", from.ID) | ||
to.APIVersion = "v1" | ||
for _, item := range from.Data { | ||
to.Data[item] = true | ||
} | ||
return to, nil | ||
func NewArticleResponse(article *data.Article) *Article { | ||
return &Article{Article: article} | ||
} |
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
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