Hi,

i want to share some more with you as i feel like it looks good to whoever 
interested into speeding up his programming experience with go ;)

Until now i presented works that took a type T and produce a derived type 
T2 of it.
Easy stuff, not so useful unless you only want to do rpc stuffs.
But still cool as this pattern helps to implement implement of 
proxy-like/facade type that are interesting.

Today i want to share a new feature i added, contextual parameters.

The methods parameters are not only meaningful by their type definition, 
but also by their names.

So it become possible to write this kind of thing and got them to work 
seamlessly,

func (t *Controller) UpdateByID(urlID int, reqBody *Tomate) *Tomate {


Simply put, 
UpdateByID look for an ID value in the URL (might be route params, query 
values),
takes the req body and somehow decodes it to an *Tomate instance.

That s it, you combine that +jsoner +httper and 
you got hundreds of lines of generated for you, 
ready to consume.
boom, lets get a beer.

That works with cookies/session/post/req/url/get because the type is 
consumed by http domain related generators (aka the context).

Also some methods parameters signature are recognized to work in the 
context of an http thing,
so you can write

func (t *Controller) TestVars1(w http.ResponseWriter, r *http.Request) {



And it just works too. the generators at each step understand them and 
behave appropriately.


But its not all, what i described is pretty interesting to maintain code 
easily,
but there s no way to declare additional information such route pattern or 
else,

So i added annotations support.


Thus i can write,

// GetByID ... 
// @route /{id} 
// @methods GET 
func (t *Controller) GetByID(urlID int) *Tomate

And get a program generated that handles all those intents for me in a 
coherent manner :D

Gonna have a beer now.


Have fun!



On Saturday, April 29, 2017 at 5:06:27 PM UTC+2, mhh...@gmail.com wrote:
>
> Hi,
>
> several generators i made to avoid some duplication.
>
> https://github.com/mh-cbon/lister
>
> Package lister is a generator to generate typed slice.
>
>
> https://github.com/mh-cbon/channeler
>
> Package channeler is a cli generator to generate channeled version of a 
> type.
>
> https://github.com/mh-cbon/mutexer
>
> Package mutexer is a cli generator to generate mutexed version of a type.
>
>
> so basically, using below code you got hundreds of line generated for you,
>
>
> in that example to make a mutexed []Tomate.
>
>
> But as it s not too stupid, or tries too, it will be able to handle 
>
> pointer and basic types
>
> mutexed []*Tomate
>
> mutexed []string
>
> ect
>
>
> It should also be able to lookup for a constructor of the src type 
> (Tomate),
>
> and reproduce it into the dest type implementation.
>
>
> There is both mutexer / channeler because both cases applies for reasons.
>
>
> The lister is a convenient way to create typed slice.
>
>
> package demo
>
> // Tomate is about red vegetables to make famous italian food.
> type Tomate struct {
>     Name string
> }
>
> // GetID return the ID of the Tomate.
> func (t Tomate) GetID() string {
>     return t.Name
> }
>
> //go:generate lister vegetables_gen.go Tomate:Tomates
> //go:generate mutexer vegetuxed_gen.go Tomates:Tomatex
>
> hth
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to