[go-nuts] batch processing RESTful requests

2020-01-29 Thread Prabhu Chawandi
Hello,

I am looking for information on how can I batch process REST API requests.
I am having a server built using GO std library "net/http" and mongoDB
being persistent storage.
Do I  need to create a separate endpoint to get this batch request and
process in the handler?
Or any other ways to achieve this? or any third party GO library existing
please point me.

Prabhu

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAP3P0byXQjW5i%2B%2BKOA1uf7AdMAcuGt9%2BJnw9ZXKTnrUtzykebw%40mail.gmail.com.


Re: [go-nuts] How to handle reading channels

2020-01-24 Thread Prabhu Chawandi
Thank you, you answered my question. I wanted to know whether I am right in
doing so or something else I am missing to read a channel all at once.

On Fri, Jan 24, 2020 at 8:09 PM Ian Lance Taylor  wrote:

> On Fri, Jan 24, 2020 at 4:25 AM Prabhu Chawandi
>  wrote:
> >
> >  I have n routines launched before reaching this select statement.
> > From the routine it will fetch response from upstream server and write
> it to channel.
> >
> > When wait count reaches  zero,  first case will be hit. I see only one
> response being read, even if 10 other go routines have written to channel.
> Shall I use range to go over rest of the contents, like below? or any other
> way is there?
> >
> > https://play.golang.org/p/kfHauJJHFtz
> >
> >  select {
> >  case v := <-stop:
> >   fmt.Println(v)
> >   for v1 := range stop {
> >fmt.Println(v1)
> >   }
> >  }
>
>
> I'm sorry, I don't understand what you are asking.  Thanks for
> providing a playground link.  That program works as I would expect.
> Perhaps you could explain what you expect it to do that is different
> from what it actually does.
>
> A single receive from a channel, as in "v := <-stop" above, will read
> a single value from the channel.  If you want to read more than one
> value from a channel, you do need to use a loop, as your program does.
>
> Ian
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAP3P0byVJv8Sija3xZyAK9TXUH%3DjEqPqLiGD%3Dn_iTc5Ys0-Cvw%40mail.gmail.com.


[go-nuts] How to handle reading channels

2020-01-24 Thread Prabhu Chawandi
Hello,

 I have n routines launched before reaching this select statement.
>From the routine it will fetch response from upstream server and write it
to channel.

When wait count reaches  zero,  first case will be hit. I see only one
response being read, even if 10 other go routines have written to channel.
Shall I use range to go over rest of the contents, like below? or any other
way is there?

https://play.golang.org/p/kfHauJJHFtz

 select {
 case v := <-stop:
  fmt.Println(v)
  for v1 := range stop {
   fmt.Println(v1)
  }
 }

Thanks.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAP3P0bwoknSej%3DKzJi55LziRCHkYD_6v4DL9%3D6RNUMUirURPOA%40mail.gmail.com.


Re: [go-nuts] Best way to buffer upstream responses in reverse proxy

2020-01-22 Thread Prabhu Chawandi
Yes, I ended up using this package. Thanks.

On Wed, Jan 22, 2020 at 2:35 AM robfig  wrote:

> You could use json iterator’s Stream type if you prefer to feel better by
> having it wrapped in a library. It does the same thing of course. As the
> name suggests it can be used to incrementally write the json to a writer if
> that’s what you’d like.
> https://godoc.org/github.com/json-iterator/go#Stream
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/202ffb33-2f22-443b-9115-35d1fd93187d%40googlegroups.com
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAP3P0bxZUTyGP8anxmG4HpUvPa-uY%3DC8gCffiem2cNCiUvKRHg%40mail.gmail.com.


[go-nuts] How to set-up go env properly

2020-01-22 Thread Prabhu Chawandi
Hello,

   I am setting up my go project directories to test. I have set up like
bellow
and my GOPATH is testexercise. Application builds fine, when I run from src/
github.com/arpsch/app/

But when I try to run go test handler from app folder, I am getting
below error . How to organize properly.

app>$go test handler

Error:
can't load package: package handler: cannot find package "handler" in any
of:
c:\go\src\handler (from $GOROOT)
C:\Users\pchawandi\projects\go\src\handler (from $GOPATH)
C:\Users\pchawandi\projects\app\src\handler

Folder structure:
testexercise
├── README.md
└── src
└── github.com
└── arpsch
└── app
├── handler
│   ├── handler.go
│   ├── handler_test.go
│   └── testData
│   └── 1.json
├── main.go
├── proxy
│   └── proxy.go
├── server
├── utils
│   ├── utils.go
│   └── utils_test.go

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAP3P0bxBhjBaY_F0eJPongHVGiZtnBt2djburVEv5WK%3DFmRsXA%40mail.gmail.com.


Re: [go-nuts] Best way to buffer upstream responses in reverse proxy

2020-01-20 Thread Prabhu Chawandi
As responses coming from upstream server, because my application acting as
proxy server and it will not have  visibility of the fields of the
responses coming.
So, think appending the characters to meet JSON format is only way. Am I
right assuming so?

On Mon, Jan 20, 2020 at 4:07 PM Tamás Gulácsi  wrote:

> Please define "better".
>
> For complexity and speed, appending "[", inserting ",", and appending "]"
> at the end is the simplest and fastest solution.
>
> If you want to check for syntax and completeness, then you should
> unmarshal, append, and then marshal again.
> But if not needed, it's just complexity and resource hog.
>
> You can hide it in a function/library, but anyway, any solution would do
> one of the two solutions specified here.
> So it will be either "hacky" or "bloat".
>
> At least when the "hacky" solution is in plain sight, you'll know where to
> check first when syntax errors araise :-)
>
> Tamás
>
> 2020. január 20., hétfő 10:19:26 UTC+1 időpontban pc a következőt írta:
>>
>> Yes, I also need to put '[' at first and ']' at last position. But I was
>> checking if there is any better way to do it. I was even having question
>> how can someone make it better without unmarshalling JSON and remarshalling
>> merged object.
>>
>>
>> On Mon, Jan 20, 2020 at 4:12 AM Tamás Gulácsi  wrote:
>>
>>> Just put the missing [,] chars wher it's required with buf.WriteByte.
>>>
>>> --
>>> 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 golan...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/golang-nuts/00bb4351-e400-46a6-aec1-05124a966410%40googlegroups.com
>>> .
>>>
>> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/71b5beb8-31e3-4894-9575-ee3c04514e2a%40googlegroups.com
> 
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAP3P0bzaFeUNnNLbiM34B_rVALpD%3DECJcR_nVvhXk1ZLyh6%3DyA%40mail.gmail.com.


Re: [go-nuts] Best way to buffer upstream responses in reverse proxy

2020-01-20 Thread Prabhu Chawandi
Yes, I also need to put '[' at first and ']' at last position. But I was
checking if there is any better way to do it. I was even having question
how can someone make it better without unmarshalling JSON and remarshalling
merged object.


On Mon, Jan 20, 2020 at 4:12 AM Tamás Gulácsi  wrote:

> Just put the missing [,] chars wher it's required with buf.WriteByte.
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/00bb4351-e400-46a6-aec1-05124a966410%40googlegroups.com
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAP3P0bzvHPbTDKiihuzMNxC40x%3DpNsgZNWh1momYTpDTVvzvfA%40mail.gmail.com.


Re: [go-nuts] Best way to buffer upstream responses in reverse proxy

2020-01-19 Thread Prabhu Chawandi
Hello,

   I am able to buffer in types.Buffer the multiple response before writing
back to client, I am hit at a problem of JSON formatting the final output.
Example: after first response buf = {...}, after second buf={...}{...}.
Now it will be returned as is, which is not in proper json format. I need
to make this like [{...},{...}]

Any hints to achieve this?

Regards,
Prabhu

On Sat, Jan 18, 2020 at 9:23 PM Prabhu Chawandi 
wrote:

> Thank you for the pointers. I will dig more into them.
>
> Thanks,
> Prabhu
>
> On Sat, Jan 18, 2020 at 12:10 PM Tamás Gulácsi 
> wrote:
>
>> Start simple: use a *bytes.Buffer, and help the GC with using a sync.Pool
>> for those buffers.
>>
>> --
>> 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.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/golang-nuts/aea5ff9b-db0f-4bb5-abfb-82a2f54f7ae1%40googlegroups.com
>> .
>>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAP3P0bzbddQZyfPtZbjOpDoQ3%3DuUZHMfYUNu4fBPYG3R1XMDvw%40mail.gmail.com.


Re: [go-nuts] Best way to buffer upstream responses in reverse proxy

2020-01-18 Thread Prabhu Chawandi
Thank you for the pointers. I will dig more into them.

Thanks,
Prabhu

On Sat, Jan 18, 2020 at 12:10 PM Tamás Gulácsi  wrote:

> Start simple: use a *bytes.Buffer, and help the GC with using a sync.Pool
> for those buffers.
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/aea5ff9b-db0f-4bb5-abfb-82a2f54f7ae1%40googlegroups.com
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAP3P0by3n5T54LhKq%3Doe5XAF%3DkbU2USY5TCE%3DYMaLF8XAmE0wg%40mail.gmail.com.


[go-nuts] Best way to buffer upstream responses in reverse proxy

2020-01-17 Thread Prabhu Chawandi
Hello,
 For a single request from a client, I have to make multiple upstream
requests and send a single response back to the client.

I am looking for best way to buffer in the proxy and write all at once,
where GC is not hurting the performance, seamlessly work for multiple
client request simultaneously.

Regards,
pc

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAP3P0bxVKVoxRpSSbcK%2BsG7rdH0rZrqLpqVT5HqmJgYmWRrarw%40mail.gmail.com.


Re: [go-nuts] Query on Interfaces

2020-01-06 Thread Prabhu Chawandi
Thank you, it is clear now.

On Tue, Jan 7, 2020 at 11:10 AM Ian Lance Taylor  wrote:

> On Mon, Jan 6, 2020 at 9:18 PM Prabhu Chawandi 
> wrote:
> >
> >   I was reading this article @
> https://blog.golang.org/laws-of-reflection
> >
> > Excerpt:
> >
> > One important detail is that the pair inside an interface always has the
> form (value, concrete type) and cannot have the form (value, interface
> type). Interfaces do not hold interface values.
> >
> > I could not understand it clearly, Can through some clarity with an
> example?
> >
> > I tried this and did not give any error.
> >
> > @ https://play.golang.org/p/Q5jRWp6MF7c
>
> Interfaces do not hold interface values.
>
> What this means is that when you write "a = b" where a and b are both
> of interface type, then the value that is in b will be copied to a.  a
> will wind up with the dynamic type and dynamic value that were
> originally in b.  The dynamic type of a will not become the type of b;
> it will become the dynamic type of the value stored in b.
>
> Ian
>


-- 
Cheers
p.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAN9r%3DsyFvWiYGf0m%2BaT6By4VhO_cGH0-V0vs%3DaffCFHfLm1ZtA%40mail.gmail.com.


[go-nuts] Query on Interfaces

2020-01-06 Thread Prabhu Chawandi
Hello,

  I was reading this article @ https://blog.golang.org/laws-of-reflection

Excerpt:

One important detail is that the pair inside an interface always has the
form (value, concrete type) and cannot have the form (value, interface
type). Interfaces do not hold interface values.

I could not understand it clearly, Can through some clarity with an example?

I tried this and did not give any error.

@ https://play.golang.org/p/Q5jRWp6MF7c


-- 
Cheers
p.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAN9r%3DsxoPvwBHScTAe3XyEtB8P02_GWVHiCNWe0kYgCnyLavVA%40mail.gmail.com.


Re: [go-nuts] Re: A question !

2020-01-04 Thread Prabhu Chawandi
Once you have little hands-on,  https://medium.com/golangspec is a great
place to read.

On Sun, Jan 5, 2020 at 9:29 AM Michael Ellis 
wrote:

> I came to Go from 10+ years of Python (and 20 years of C before that).  Go
> By Example  was the online resource I found
> most useful in first few weeks of learning the language.  I also highly
> recommend getting a copy of The Go Programming Language
> and working your way through the chapters.
>
> For specific questions, this forum and Stack Overflow are both excellent.
>
> Finally, it's been my experience that actually getting things done in any
> language comes down to mastery of its standard library. Plan to spend a lot
> of time in https://golang.org/pkg/.
>
> Good luck in your journey!
>
> On Saturday, January 4, 2020 at 1:28:24 PM UTC-5, Motaz Hejaze wrote:
>>
>> 2 - What is the fastest resource to learn Golang ( efficiently ) ?
>>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/e8d44ee2-4fa5-4078-85b8-48eb84354ca3%40googlegroups.com
> 
> .
>


-- 
Cheers
p.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAN9r%3Dsyy-TMg3qVxdpn39U_YK%2B9gpiJeNDPVhuhWHRkZettBkQ%40mail.gmail.com.


Re: [go-nuts] How to fill a map with requests from client

2020-01-03 Thread Prabhu Chawandi
all["client request"] =  clientJob.name// append the client requests on map

Maps are Key: Value pair, in your case as the same key ie.  "client
request"  is being used, the latest value is overwriting the previous
value. Add a unique key for each request to store them in same map.

On Fri, Jan 3, 2020 at 12:44 PM snk  wrote:

> I am a beginner in Golang, This is a TCP server that receives requests and
> sends back a hello message to the client attached with the client's
> message(name)
>  *how can I fill those requests into a map without erasing the previous
> request?*
>  this is the code, the request is appended to the map but when the next
> comes, it replaces the current on.
>
>
>  // Goroutine and Socket programming TCP server
> //**
> // TCP
> //--
>
> package main
>
> import (
> "bufio"
> "fmt"
> "net"
> "time"
> )
> // check if there is any error and send a message. but it's better to remove 
> panic later (it's not recommended to use it)
> //***
> func check(err error, message string) {
> if err != nil {
> panic(err)
> }
> fmt.Printf("%s\n", message)
> }
> // Create the client structure that contains the client's name and the 
> connection
> //
>
> type ClientJob struct {
> name string
> conn net.Conn
>
> }
>
> // Create the function,the channel with type struct
> //*
>
> func generateResponses(clientJobs chan ClientJob) {
> for {
> // Wait for the next job to come off the queue.
> clientJob := <-clientJobs
>
> // Do something thats keeps the CPU buys for a whole second.
> for start := time.Now(); time.Now().Sub(start) < time.Second; {
> }
>
> // Send back the response.
>
> clientJob.conn.Write([]byte("Hello, " + clientJob.name))
>
> //clientJob:=make(chan ClientJob)
> //name:=make(chan string)
> //name:=<-clientJobs
>
> all := make(map[string]string) // create the map
> all["client request"] =  clientJob.name// append the client requests 
> on map
> fmt.Println("All requests in the slice", all) // show all the 
> requests in the map
>
>
>
> }
>
> }
>
> // The main function
> //***
>
> func main() {
> clientJobs := make(chan ClientJob) // declare the channel used in the 
> function above
> go generateResponses(clientJobs)  // put the function in a goroutine
>
> ln, err := net.Listen("tcp", ":8080") // connect to the port 8080, it can 
> be changed to any port if needed
> check(err, "Server is ready.") // show the message that the server is 
> ready to receive
> //fmt.Println(<-clientJobs)
> // start checking the connection et receiving from the client and pass it 
> into a goroutine and send it via a channel ClientJobs<-ClientJob{name, conn}
> for {
> conn, err := ln.Accept()
> check(err, "Accepted connection.")
>
> go func() {
> buf := bufio.NewReader(conn)
>
> for {
> name, err := buf.ReadString('\n')
>
> if err != nil {
> fmt.Printf("Client disconnected.\n")
> break
> }
>
> clientJobs <- ClientJob{name, conn} // pass the name and conn 
> to the clientJobs channel
>
> }
>
>
> }()
> }
> }
>
>
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/2457abfa-04c9-476c-a2e4-b86e8e49e012%40googlegroups.com
> 
> .
>


-- 
Cheers
p.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAN9r%3DsxMH0e2_Y6zhg-hCHgOvXem2SLKGkpn2ToPTi7LEeDWFg%40mail.gmail.com.