Hi,

Some more about that.

I added tow new generators jsoner / httper.

jsoner takes a type in input, 
parses method args from a json body req, 
output func params to a json body response.
JSON-RPC.

httper, takes an http req in input,
interprets it as a json-rpc request,
pass it to the underlying RPC decoder (jsoner?)
and handle the response.

Still work to be done,
but looks at this main to get a json api,

package main

import (
    "log"
    "net/http"
)

// 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 jsoner json_vegetables_gen.go *Tomates:JSONTomates
//go:generate httper http_vegetables_gen.go *JSONTomates:HTTPTomates

func main() {

    backend := NewTomates()
    backend.Push(Tomate{Name: "red"})
    jsoner := NewJSONTomates(backend)
    httper := NewHTTPTomates(jsoner)

    // public views
    http.HandleFunc("/", httper.At)

    /*
        curl -H "Accept: application/json" -H "Content-type: 
application/json" -X POST -d ' {"i":0}'  http://localhost:8080/
    */

    log.Fatal(http.ListenAndServe(":8080", nil))
}


Last note: can generics handle that ? (I dont think so)

On Saturday, April 29, 2017 at 5:08:52 PM UTC+2, mhh...@gmail.com wrote:
>
> i forgot to say at the end, id love to be able to do
>
> cat mystruct.go | lister Tomates | mutexer Tomatex | ....
>
> That d be awesome! :D
>
> 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