Re: [go-nuts] Re: Query regarding net/http/cookiejar: Cookies() method and Expiry/MaxAge

2022-07-01 Thread Amit Saha
On Fri, Jul 1, 2022 at 7:08 PM Amit Saha wrote: > > On Thu, Jun 30, 2022 at 4:16 PM Volker Dobler > wrote: > >> On Thursday, 30 June 2022 at 00:31:29 UTC+2 amits wrote: >> >>> Currently the Cookies() method as explained at >>> https://pkg.go.dev/net/htt

Re: [go-nuts] Re: Query regarding net/http/cookiejar: Cookies() method and Expiry/MaxAge

2022-07-01 Thread Amit Saha
On Thu, Jun 30, 2022 at 4:16 PM Volker Dobler wrote: > On Thursday, 30 June 2022 at 00:31:29 UTC+2 amits wrote: > >> Currently the Cookies() method as explained at >> https://pkg.go.dev/net/http/cookiejar#Jar.Cookies only adds the Name and >> Value of the cookies and strips out the MaxAge and

Re: [go-nuts] Query regarding net/http/cookiejar: Cookies() method and Expiry/MaxAge

2022-07-01 Thread Amit Saha
server -> Reads the cookies -> Set-Cookie header flow triggered? (?? -> not quite sure) > - sean > > > On Wed, Jun 29, 2022 at 11:31 PM Amit Saha wrote: > >> Hi all, >> >> Currently the Cookies() method as explained at >> https://pkg.go.dev/ne

[go-nuts] Query regarding net/http/cookiejar: Cookies() method and Expiry/MaxAge

2022-06-29 Thread Amit Saha
Hi all, Currently the Cookies() method as explained at https://pkg.go.dev/net/http/cookiejar#Jar.Cookies only adds the Name and Value of the cookies and strips out the MaxAge and Expires field (and all other fields). Presumably, as I can see in the code, the logic is if a cookie is returned as a

[go-nuts] Re: Setting a cookie - Expires needed with MaxAge?

2022-05-18 Thread Amit Saha
On Thu, May 19, 2022 at 7:59 AM Amit Saha wrote: > > > > On Thu, May 19, 2022 at 7:02 AM Amit Saha wrote: >> >> Hi all, >> >> For a cookie, it seems like both, `Expires` and `MaxAge` must be specified? The expectation is that, only Max-Age should

[go-nuts] Re: Setting a cookie - Expires needed with MaxAge?

2022-05-18 Thread Amit Saha
On Thu, May 19, 2022 at 7:02 AM Amit Saha wrote: > Hi all, > > For a cookie, it seems like both, `Expires` and `MaxAge` must be > specified? The expectation is that, only Max-Age should be sufficient. > > // valid > c1 := http.Cookie{ > Expires: time.Now().Add

Re: [go-nuts] Setting a cookie - Expires needed with MaxAge?

2022-05-18 Thread Amit Saha
On Thu, May 19, 2022 at 7:43 AM Robert Engels wrote: > > Your first case doesn’t even work - nil is output. That's a nil error - the return value from Valid() - indicating that the cookie is valid. > > > On May 18, 2022, at 4:11 PM, Amit Saha wrote: > >  > Hi all, &g

[go-nuts] Setting a cookie - Expires needed with MaxAge?

2022-05-18 Thread Amit Saha
Hi all, For a cookie, it seems like both, `Expires` and `MaxAge` must be specified? The expectation is that, only Max-Age should be sufficient. // valid c1 := http.Cookie{ Expires: time.Now().Add(3600 * 24 * time.Second), MaxAge: 24 * 3600, // 24 hours } // invalid c2 :=

[go-nuts] Re: when EOF returned from http client.Post, client can continue to be used ?

2022-04-18 Thread Amit Saha
On Monday, April 18, 2022 at 6:17:30 PM UTC+10 toon@gmail.com wrote: > I did experiment but when using the same client I immediately got an EOF > again. But that might also have been due to the rate-limiting. That's interesting. Could you try printing the response status or writing

[go-nuts] Re: when EOF returned from http client.Post, client can continue to be used ?

2022-04-17 Thread Amit Saha
On Sunday, April 17, 2022 at 11:52:17 PM UTC+10 toon@gmail.com wrote: > It is not clear to me from the documentation whether I can continue to use > an http.Client after a POST failed (due to the connection being closed ; > In my case the connection closes probably due to rate-limiting).

[go-nuts] Re: sql: converting argument $10 type: unsupported type main.RequestRecord, a struct

2022-01-28 Thread Amit Saha
On Saturday, January 29, 2022 at 5:12:48 AM UTC+11 kimiyas...@gmail.com wrote: > Hi > > i have a struct event and inner that i have struct RequestRecord > *type RequestRecord struct {* > * ID string `json:"id"`* > * Addr string `json:"addr"`* > * Host string `json:"host"`* > * Method string

[go-nuts] Re: How to distribute database connection across all golang file ?

2022-01-08 Thread Amit Saha
The usual pattern is to have a global *sql.Db object obtained via calling the Open() function as explained at [1]. You don't have to worry about maintaining the connection pool yourselves as that's automatically done. The Go tutorial on the topic [2] shows you can do this using a global

[go-nuts] Self promotion - New Book, "Practical Go: Building Scalable Network and Non-Network Applications"

2021-12-20 Thread Amit Saha
Hi all, I wanted to share that my latest book is on Go programming and it is now out electronically as well as in print. It is titled "Practical Go: Building Scalable Network and Non-Network Applications" (https://practicalgobook.net/) and published by Wiley publications. The book targets readers

Re: [go-nuts] Interactive input and "go test"

2021-11-05 Thread Amit Saha
On Fri, Nov 5, 2021 at 11:24 PM Amit Saha wrote: > > > > On Fri, 5 Nov 2021, 11:08 pm Axel Wagner, > wrote: >> >> First, to point out the obvious: It is a bad idea to have a test read from >> stdin. You should pass a separate io.Reader and use that. >>

Re: [go-nuts] Interactive input and "go test"

2021-11-05 Thread Amit Saha
gt; instead test a function which uses a general io.Reader. > Great thank you for clarifying that. I ran into this as I was writing a test for an interactive input function and I expected the test to hang but it didn't. So bit of an accidental find and glad I found this. > On Fri, Nov 5, 20

Re: [go-nuts] Interactive input and "go test"

2021-11-05 Thread Amit Saha
> On 5 Nov 2021, at 10:27 pm, Amit Saha wrote: > > I have this test function: > > package main > > import ( > "bufio" > "fmt" > "os" > "testing" > ) > > func TestInput(t *t

[go-nuts] Interactive input and "go test"

2021-11-05 Thread Amit Saha
I have this test function: package main import ( "bufio" "fmt" "os" "testing" ) func TestInput(t *testing.T) { scanner := bufio.NewScanner(os.Stdin) msg := "Your name please? Press the Enter key when done" fmt.Fprintln(os.Stdout, msg)

Re: [go-nuts] Does the module name have to include the repo name when you publish a Go module?

2021-09-07 Thread Amit Saha
On Wed, 8 Sept 2021, 5:34 am Dean Schulze, wrote: > If you are going to publish a Go module does the module name have to > include the repo name? I couldn't find this documented anywhere but > through trial and error I've discovered that it is required. > > I named my module like this and

Re: [go-nuts] Re: Logging libraries and standard library compatibility

2021-08-31 Thread Amit Saha
On Tue, Aug 31, 2021 at 9:46 PM Robert Engels wrote: > > The io.Writer is too low level to be useful. Imagine a logger that wants to > send an sms on severe errors only. > > The best solution is to declare your own logger interface - but similar to > the collections discussion it would better

Re: [go-nuts] Re: Logging libraries and standard library compatibility

2021-08-30 Thread Amit Saha
On Tue, Aug 31, 2021 at 8:58 AM Kevin Chowski wrote: > To the original poster: can you just declare your own Logger-like interface > and allow users of your library to pass whatever logging implementation they > have? In what ways are you thinking that you're forced to be coupled with the

Re: [go-nuts] Array of structure and html templates.

2021-08-29 Thread Amit Saha
On Mon, Aug 30, 2021 at 12:01 PM Victor Medrano wrote: > > I.m new to go, and working with a web aplicación I need to pass a tray of > struct to the template. > something like this > > type Month struct { > Mname string > Color string > Id int > } > > > type Year struct { > Yname, Color string

[go-nuts] Logging libraries and standard library compatibility

2021-08-28 Thread Amit Saha
Hi all, a huge disclaimer - I am not familiar with the design decisions and internal details of anything that follows. They are coming from the point of view of a consumer of the language and the ecosystem and also someone trying to write about these things for an audience. Say I have an

Re: [go-nuts] Re: Problem with 0MQ and goLang on Windows

2021-08-23 Thread Amit Saha
On Tue, Aug 24, 2021 at 8:55 AM Dominique Kande Vita wrote: > > Hi All, > > this is a kind of old problem. I am dropping here my solution, just in case > someone will search for as crazy all over the net. > 1. add in your PATH (environement variable) the bin folder where vcpkg has > compiled

Re: [go-nuts] New to Unit Testing - Testing HTTP requests and response codes

2021-08-17 Thread Amit Saha
> On 18 Aug 2021, at 5:47 am, 'Beginner' via golang-nuts > wrote: > > Hey, so I am pretty new to Golang and Unit tests as a whole. Right now I am > trying to create some tests for this section of code. I want to test in the > case of an unexpected HTTP response but I don't know how or where

Re: [go-nuts] Re: What are the options to fake SQL database for testing?

2021-08-06 Thread Amit Saha
On Thu, Jul 29, 2021 at 5:13 PM Brian Candler wrote: > > You might also want to look at podman, which runs containers directly as > processes under your own userid with no docker daemon - and buildah, the > corresponding tool for creating container images. I use them quite a lot for >

Re: [go-nuts] Showing effective replace in go modules

2021-08-01 Thread Amit Saha
s. > > On Thu, Jul 29, 2021 at 9:54 PM Amit Saha wrote: >> >> Say, i have a module A (github.com/username/foo/v1) with a replace of >> a third-party package in its go.mod: >> >> replace github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt >> v3.2.1+

[go-nuts] Showing effective replace in go modules

2021-07-29 Thread Amit Saha
Say, i have a module A (github.com/username/foo/v1) with a replace of a third-party package in its go.mod: replace github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt v3.2.1+incompatible Now, i require module A/v1 package from module A in my module B containing the main package: require

Re: [go-nuts] Re: What are the options to fake SQL database for testing?

2021-07-28 Thread Amit Saha
On Thu, Jul 29, 2021 at 4:39 AM Marcin Romaszewicz wrote: > > I have this exact testing issue at my company, we have many Go services which > use Postgres in production, but are unit tested against SQLite. > > The latest SQLite covers the vast majority of Postgres queries, so most tests >

Re: [go-nuts] Re: What are the options to fake SQL database for testing?

2021-07-28 Thread Amit Saha
rd... What I have >>>> seen many times is just to have a "seed-based" local database that is used >>>> in local integration tests. >>>> Another, quite efficient solution is to have a test suite's database >>>> initialized once and used

Re: [go-nuts] Re: What are the options to fake SQL database for testing?

2021-07-28 Thread Amit Saha
unit tests for your database-interacting low-level functions, and >> integration tests for the whole flow, you can just mock the db behavior in >> other higher level unit tests because you know it'll work in production. >> >> Hope this helps! >> >> Le mar

Re: [go-nuts] Re: What are the options to fake SQL database for testing?

2021-07-28 Thread Amit Saha
what i think of as testing it at various layers - if you test the code which is close to the DB well, you can then take advantage of simple mocks at higher levels. > > Le mar. 27 juil. 2021 à 10:04, Amit Saha a écrit : >> >> Hi all, >> >> I am just looking at options to

[go-nuts] Re: What are the options to fake SQL database for testing?

2021-07-27 Thread Amit Saha
Hi all, I am just looking at options to write tests for parts of my application that interacts with a SQL database. So far it seems like the community has few distinct schools of thought: - Mocks (For e.g. using https://pkg.go.dev/github.com/DATA-DOG/go-sqlmock) - In-memory "real" DB solutions

[go-nuts] Panic recovery in net/http Server

2021-07-16 Thread Amit Saha
I recently posted a query [1] to the grpc mailing list to clarify a behavior in the Go gRPC server - a panic() in a request handler function would terminate the server process. Now, I know that's not the case in the net/http server implementation - a demo here [2]. However, the interesting thing

Re: [go-nuts] Re: Go on Windows 10 ARM

2021-07-14 Thread Amit Saha
On Thu, 15 July 2021, 1:32 am Nate, wrote: > Go 1.17rc1 is available, and you may now grab a copy for Windows 10 ARMv8 > on the downloads page . Thank you. > On Wednesday, June 30, 2021 at 10:14:14 PM UTC-4 amits...@gmail.com wrote: > >> Hi all - I am

Re: [go-nuts] Go on Windows 10 ARM

2021-07-01 Thread Amit Saha
On Fri, 2 July 2021, 12:36 am Federico Damián Schonborn, < fdschonb...@gmail.com> wrote: > Support for Windows ARM64 is being added in Go 1.17 (currently in beta), > see: https://tip.golang.org/doc/go1.17#windows > Thanks. > El jue, 1 de jul. de 2021 a la(s) 02:15, A

Re: [go-nuts] Go on Windows 10 ARM

2021-06-30 Thread Amit Saha
On Thu, Jul 1, 2021 at 12:52 PM Kurtis Rader wrote: > > On Wed, Jun 30, 2021 at 7:14 PM Amit Saha wrote: >> >> Hi all - I am curious if anybody has installed the Go toolchain on >> Windows 10 ARM 64? > > > You might need to clarify your question. Go is officiall

[go-nuts] Go on Windows 10 ARM

2021-06-30 Thread Amit Saha
Hi all - I am curious if anybody has installed the Go toolchain on Windows 10 ARM 64? Thanks, Amit. -- 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

Re: [go-nuts] Representing Optional/Variant Types Idiomatically (or not)

2021-06-17 Thread Amit Saha
On 17 Jun 2021, at 5:43 pm, Joshua wrote: Hello, I have 2 questions about idiomatic ways to represent optional values, and variant values in types. 1) I'm modelling a data type which has a field which may or may not be there, would most Gophers reach for a pointer here, and use `nil' to

Re: [go-nuts] Re: Understanding how []byte("astring") works

2021-06-14 Thread Amit Saha
On Mon, Jun 14, 2021 at 11:42 AM peterGo wrote: > > Amit, > > Compilers implement a specification: > > The Go Programming Language Specification > https://golang.org/ref/spec > > Conversions > > A conversion changes the type of an expression to the type specified by the > conversion. A

Re: [go-nuts] Understanding how []byte("astring") works

2021-06-14 Thread Amit Saha
On Mon, Jun 14, 2021 at 3:23 PM Roland Müller wrote: > > Hello, > > Am Mo., 14. Juni 2021 um 03:24 Uhr schrieb Amit Saha : >> >> Hi - My main motivation to understand this is i always had to google >> this - how to convert a string to a byte slice. >> >&

Re: [go-nuts] Understanding how []byte("astring") works

2021-06-14 Thread Amit Saha
On Mon, Jun 14, 2021 at 4:44 PM Axel Wagner wrote: > > Hi, > > On Mon, Jun 14, 2021 at 2:24 AM Amit Saha wrote: >> >> Hi - My main motivation to understand this is i always had to google >> this - how to convert a string to a byte slice. >> >&

[go-nuts] Understanding how []byte("astring") works

2021-06-13 Thread Amit Saha
Hi - My main motivation to understand this is i always had to google this - how to convert a string to a byte slice. Is []byte a type that has been defined in the compiler? Or, is that an internal level detail that an earlier stage (parsing) takes care of when the compiler sees that statement?

Re: [go-nuts] unpacking map[string]interface{} answer

2021-05-31 Thread Amit Saha
> On 31 May 2021, at 6:08 pm, natxo@gmail.com > wrote: > > ok, I think I understand how this library works, and posting this for future > reference in case someone needs it. > > The library uses this other library: > https://github.com/mitchellh/mapstructure >

Re: [go-nuts] Re: signal.NotifyContext - Does it expose the signal handled?

2021-05-21 Thread Amit Saha
Thanks. On Sat, 15 May 2021, 12:48 am Vladimir Varankin, wrote: > I don't think the current API provides that functionality. > > In the original proposal for signal.NotifyContext, there were several > discussions, including related to what features the new API should provide. > The consensus

[go-nuts] signal.NotifyContext - Does it expose the signal handled?

2021-05-13 Thread Amit Saha
Hi - i took a brief look and it doesn't look like we can access the signal that was handled via the signal.NotifyContext() function call? It could be useful for logging messages. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe

Re: [go-nuts] Fwd: protoc-gen-go and go modules

2021-05-13 Thread Amit Saha
sense once you've cogitated on it. > Thanks. I think I get it. So the repo containing the .proto files would have a .go file with the generate directives to do the necessary generation. And the go.mod file of course. > On Wed, May 12, 2021 at 18:47 Amit Saha wrote: > >> Hi all, this is onl

[go-nuts] Fwd: protoc-gen-go and go modules

2021-05-12 Thread Amit Saha
Hi all, this is only relevant to people using grpc. I posted the query below to the grpc mailing list, thought of posting it here as welll. How are you importing the generated definitions and other resources them into your server and client? As far as I see it now, the protoc command will not

Re: [go-nuts] New advanced, CGo-free SQLite package

2021-05-01 Thread Amit Saha
a fork instead. Ah, thanks! About the fork, I sent a PR for your github repo fixing the URL, which is what led me to quickly think that the upstream was missing. > > -Ross > > On April 30, 2021, Amit Saha wrote: > > Hi Ross, Thanks for sharing this. I am curious what's the differe

Re: [go-nuts] New advanced, CGo-free SQLite package

2021-05-01 Thread Amit Saha
Hi Ross, Thanks for sharing this. I am curious what's the difference between your fork and the original repo (which is now gone it seems)? On Fri, Apr 30, 2021 at 11:42 PM Ross Light wrote: > > I've created a new Go package for SQLite: zombiezen.com/go/sqlite > > It is a fork of

Re: [go-nuts] HTTP request reading

2021-04-30 Thread Amit Saha
> On 29 Apr 2021, at 11:27 pm, K. Alex Mills wrote: > > Partial responses inline, HTH. > > On Thu, Apr 29, 2021, 6:09 AM Amit Saha <mailto:amitsaha...@gmail.com>> wrote: > Hi all, when an incoming request comes in, does the ListenAndServe() > function rea

[go-nuts] HTTP request reading

2021-04-29 Thread Amit Saha
Hi all, when an incoming request comes in, does the ListenAndServe() function read the first line (as explained in https://developer.mozilla.org/en-US/docs/Web/HTTP/Messages) to figure out whether there is a handler registered or not for the path and then simply hands it over to the handler (if

Re: [go-nuts] tests, init() and flags

2021-04-24 Thread Amit Saha
On Sun, Apr 25, 2021 at 7:10 AM Shivendra Singh wrote: > > Yes @Jan Mercl absolutely correct!! > > Able to figure out a solution. > Basically the go mod i am using as part of the code is doing something like > this : > func init() { > //reads vars > flag.Parse() > } > > The problem arises when

Re: [go-nuts] Purpose of TimeoutHandler

2021-04-24 Thread Amit Saha
> On 19 Apr 2021, at 10:07 pm, Amit Saha wrote: > > Thank you, I was suspecting that this might be the way to do it. This is another approach I thought would also work without using channels or where you are just running a sequence of steps in a handler: func handle

Re: [go-nuts] Re: Purpose of TimeoutHandler

2021-04-19 Thread Amit Saha
Thank you, I was suspecting that this might be the way to do it. On Mon, 19 Apr 2021, 6:02 pm Brian Candler, wrote: > Your inner request handler needs to use the request context to cancel its > work. > > package main > > import ( > "log" > "net/http" > "time" > ) > > type foo struct{} > >

[go-nuts] Purpose of TimeoutHandler

2021-04-18 Thread Amit Saha
Hi all - I wrongly assumed that the TimeoutHandler() is supposed to help application authors free up resources on the sever for anything running than the expected duration of time. However that doesn’t seem to be the case. The inner handler continues running, only the client gets a 503 after

Re: [go-nuts] Go 1.16 and modules

2021-03-28 Thread Amit Saha
On Mon, Mar 29, 2021 at 12:15 PM Reto wrote: > > On Mon, Mar 29, 2021 at 11:18:28AM +1100, Amit Saha wrote: > > "Module-aware mode is enabled by default, regardless of whether a > > go.mod file is present in the current working directory or a parent > > directory. Mo

[go-nuts] Go 1.16 and modules

2021-03-28 Thread Amit Saha
Hi Folks, I just realized that with Go 1.16, you must create a module via go mod init, even if you are writing a simple hello world program. The most surprising aspect to me was that I can only know that's the case if I don't have a go.mod file anywhere in the parent directory chain. It becomes

Re: [go-nuts] Use cases for custom ResponseWriter

2021-03-18 Thread Amit Saha
gt; net/http/httptest contains an implementation of http.ResponseWriter that's >> used for testing request handlers in isolation (without spinning up a >> server). Thanks both of you! >> >> On 17.03.21 03:12, Amit Saha wrote: >> >> Hi all, >> >> I ca

[go-nuts] Use cases for custom ResponseWriter

2021-03-16 Thread Amit Saha
Hi all, I came across the need for writing a custom ResponseWriter when I wanted to log the response status code. Is there any other use case where this is needed to implement one? Thanks and appreciate any pointers. Best Regards, Amit. -- You received this message because you are subscribed

Re: [go-nuts] Error while executing exec.command

2021-03-15 Thread Amit Saha
On Tue, 16 Mar 2021, 9:37 am Sharan Guhan, wrote: > Hi Experts, > > I am relatively new to GOLANG and trying a simple program as below which > is failing in fetching the output of a file, which works otherwise on the > command prompt: > > Lang : GOLANG > OS : Linux/Centos > Problem : Using

Re: [go-nuts] still struggling to understand modules

2021-02-23 Thread Amit Saha
On Wed, Feb 24, 2021 at 12:49 PM rob wrote: > > Hi. I'm a hobby programmer. I've been able to learn and use gopath > mode for a while. I've accumulated 20+ programs that I use that were > build using gopath mode. I'm not using a package manager, as all my > code is in GOPATH, ie, ~/go/src/ >

Re: [go-nuts] Clarification related to HTTP request context cancellations and goroutines

2021-01-08 Thread Amit Saha
go func() { log.Println("Second expensive operation") time.Sleep(5 * time.Second) done <- true }() if clientDisconnected(r.Context(), done) { return } fmt.Fprintf(w, "All operations d

[go-nuts] Re: HTTP RequestWithContext in a server and error handling pattern

2021-01-08 Thread Amit Saha
> On 9 Jan 2021, at 9:50 am, Amit Saha wrote: > > Say I have created a RequestWithContext: > > r, err := http.NewRequestWithContext(ctx, "GET", > "http://127.0.0.1:8080/healthcheck;, nil) > > Now, I make the request in the context of *another* HTTP

[go-nuts] HTTP RequestWithContext in a server and error handling pattern

2021-01-08 Thread Amit Saha
Say I have created a RequestWithContext: r, err := http.NewRequestWithContext(ctx, "GET", "http://127.0.0.1:8080/healthcheck;, nil) Now, I make the request in the context of *another* HTTP request handling function: Func myHandler(w http.ResponseWriter, r *http.Request) { ... resp, err :=

[go-nuts] Clarification related to HTTP request context cancellations and goroutines

2021-01-07 Thread Amit Saha
Hi all, I want to confirm whether my understanding related to handling HTTP client disconnections is correct or not. Consider this: func longRunningProcessing(ctx context.Context, w http.ResponseWriter) { done := make(chan bool) go func() { expensiveWork() # This is a blocking

Re: [go-nuts] Clarification in the description of context.WithValue()

2021-01-06 Thread Amit Saha
- use a separate type for key. > I would also argue, that the code is clearer and safer that way - because > there can only be one value of type ctxKey{}, you don't have to wonder what > would happen if you use different keys of the same type I agree, I was thinking the same. Thank you.

Re: [go-nuts] Clarification in the description of context.WithValue()

2021-01-06 Thread Amit Saha
currentCtx, requestContext{}, c) req = req.WithContext(newCtx) Retrieve the data somewhere else during processing the request: ctx := req.Context() v := ctx.Value(requestContext{}) if m, ok := v.(requestContext); ok { log.Printf("Processing request: %v", m) } Is this inefficient?

Re: [go-nuts] Clarification in the description of context.WithValue()

2021-01-06 Thread Amit Saha
On Thu, Jan 7, 2021 at 9:48 AM Axel Wagner wrote: > > > > On Wed, Jan 6, 2021 at 11:39 PM Amit Saha wrote: >> >> Is it fair to say then that any user-defined type here is acceptable as a >> key? > > > No. You can create a user-defined type out of *an

Re: [go-nuts] Clarification in the description of context.WithValue()

2021-01-06 Thread Amit Saha
On Thu, Jan 7, 2021 at 9:33 AM Axel Wagner wrote: > > On Wed, Jan 6, 2021 at 11:31 PM Amit Saha wrote: >> >> In the description of context.WithValue(), we have: >> >> The provided key must be comparable and should not be of type string >> or any other built

[go-nuts] Clarification in the description of context.WithValue()

2021-01-06 Thread Amit Saha
In the description of context.WithValue(), we have: The provided key must be comparable and should not be of type string or any other built-in type to avoid collisions between packages using context. Users of WithValue should define their own types for keys. To avoid allocating when assigning to

Re: [go-nuts] json.NewDecoder()/Decode() versus Unmarshal() for single large JSON objects

2020-12-29 Thread Amit Saha
On Wed, Dec 30, 2020 at 4:07 AM Amnon wrote: > > How do you know, if you don't check? FTR, it's not just about sending > garbage, it's also about requests accidentally being truncated or just > generally garbled. > > json.NewDecoder(r.Body).Decode() will return an error if the request > is

Re: [go-nuts] json.NewDecoder()/Decode() versus Unmarshal() for single large JSON objects

2020-12-29 Thread Amit Saha
enated json > documents `Decoder` is not actually doing what you want. Indeed, thank you for the explanation. > > On Tue, Dec 29, 2020 at 11:37 AM Amit Saha wrote: >> >> On Tue, Dec 29, 2020 at 11:35 AM burak serdar wrote: >> > >> > On Mon, Dec 28, 2020 at

Re: [go-nuts] json.NewDecoder()/Decode() versus Unmarshal() for single large JSON objects

2020-12-29 Thread Amit Saha
On Tue, Dec 29, 2020 at 11:35 AM burak serdar wrote: > > On Mon, Dec 28, 2020 at 5:22 PM Amit Saha wrote: > > > > Hi all, let's say I am a single large JSON object that I want to > > process in my HTTP server backend. > > > > I am trying to get my hea

[go-nuts] json.NewDecoder()/Decode() versus Unmarshal() for single large JSON objects

2020-12-28 Thread Amit Saha
Hi all, let's say I am a single large JSON object that I want to process in my HTTP server backend. I am trying to get my head around if there is any performance advantage - memory or CPU to use the json.NewDecoder()/Decode() mechanism versus the Unmarshal() function? Thanks, Amit -- You

Re: [go-nuts] json objects

2020-12-25 Thread Amit Saha
On Sat, 26 Dec 2020, 10:25 am Hamsa Hesham, wrote: > package main > import "encoding/json" > import "log" > import "fmt" > > type book struct { > IDint > title string > pubDate string > authorstring > genre string > publisher string > language

Re: [go-nuts] assigning to an http request in a handler

2020-12-21 Thread Amit Saha
On Tue, Dec 22, 2020 at 3:49 AM zilto karamazov wrote: > > > Hello, > > I'm wondering if it is ok to do this ? > > > package main > > import ( > "context" > "fmt" > "log" > "net/http" > > "github.com/gorilla/mux" > ) > > func main() { > addr :=

Re: [go-nuts] Re: 1.16 beta 1 - Getting an error trying to use the "embed" package

2020-12-18 Thread Amit Saha
On Sat, 19 Dec 2020, 5:45 am Ian Lance Taylor, wrote: > On Fri, Dec 18, 2020 at 4:50 AM Amit Saha wrote: > > > > On Fri, 18 Dec 2020, 11:44 pm Volker Dobler, > wrote: > >> > >> Use > >> > >> import _ "embed" // note the _

Re: [go-nuts] Re: 1.16 beta 1 - Getting an error trying to use the "embed" package

2020-12-18 Thread Amit Saha
On Fri, 18 Dec 2020, 11:44 pm Volker Dobler, wrote: > Use > > import _ "embed" // note the _ > > Your code does not use package embed. A comment does > not qualify as usage. As yous must import it for //go:embed > comments to work you have to use a "side-effects-only"-import. > Ah yes.

[go-nuts] Go 1.16 Beta 1 - Clarification regarding module

2020-12-18 Thread Amit Saha
Hi all, The release notes has this: Module-aware mode is enabled by default, regardless of whether a go.mod file is present in the current working directory or a parent directory. More precisely, the GO111MODULE environment variable now defaults to on. To switch to the previous behavior, set

[go-nuts] 1.16 beta 1 - Getting an error trying to use the "embed" package

2020-12-18 Thread Amit Saha
Hi all, has anyone tried using the “embed” package in the 1.16 beta 1 release? My data.go file looks as: package main import "embed" //go:embed templates/main.go.tmpl var tmplMainGo []byte When I build the program, I get this: ~/go/bin/go1.16beta1 build

Re: [go-nuts] What are debian:buster-slim advantages vs alpine ones?

2020-12-15 Thread Amit Saha
On Wed, 16 Dec 2020, 12:38 pm Constantine Vassilev, wrote: > All examples in Google Cloud Run for building > Golang Docker images are based on Debian. > > FROM golang:alpine AS builder > ... > FROM debian:buster-slim > ... > > What are debian:buster-slim advantages vs alpine ones? > Besides

Re: [go-nuts] Purpose of pattern in muxEntry

2020-12-15 Thread Amit Saha
> On 16 Dec 2020, at 5:49 am, jake...@gmail.com wrote: > > I have no special knowledge of the code, but it looks like the reason is so > that ServeMux.es , which is a []muxEntry, can be > searched. See the latter half of `func (mux *ServeMux) match() >

[go-nuts] Purpose of pattern in muxEntry

2020-12-14 Thread Amit Saha
Hi all, the ServerMux struct is currently defined as: type ServeMux struct { // other fields m map[string]muxEntry } The muxEntry is then defined as: type muxEntry struct { h Handler pattern string } Is there any reason for also storing the pattern in the muxEntry since it

Re: [go-nuts] Production Support

2020-12-09 Thread Amit Saha
Hi - your message sounds interesting. Why not open source your code? On Thu, 10 Dec 2020, 10:17 am jm...@tele-metron.com, wrote: > I have developed an API server using GO. Started as a retirement project > but now has actual company that is ready to replace their current > technology. I am

Re: [go-nuts] When does net/http's Client.Do return io.EOF?

2020-12-09 Thread Amit Saha
> On 7 Dec 2020, at 10:58 pm, 'Axel Wagner' via golang-nuts > wrote: > > We recently had the same issue. > > On Mon, Dec 7, 2020 at 11:58 AM Gregor Best wrote: > Hi! > > We're using a 3rd party provider's API to handle some of our customer > requests. Interaction with their API consists

Re: [go-nuts] Trying to understand HTTP connection pooling behaviour - new DNS lookup

2020-11-28 Thread Amit Saha
> On 28 Nov 2020, at 11:22 pm, b.ca...@pobox.com wrote: > > > My actual query was to learn how the removal of the broken connection is > > done. > > Ah OK. I'm not familiar with this code (net/http/transport.go), and you've > already shown that the PutIdleConn trace action isn't called.

Re: [go-nuts] Trying to understand HTTP connection pooling behaviour - new DNS lookup

2020-11-28 Thread Amit Saha
> On 28 Nov 2020, at 10:36 pm, b.ca...@pobox.com wrote: > > Unless you timestamp those log lines, I don't see any evidence that the DNS > query is done when the godoc server shuts down. Could it not just be that > after the 2 second sleep, when it's time to make a new connection, it finds

Re: [go-nuts] Trying to understand HTTP connection pooling behaviour - new DNS lookup

2020-11-28 Thread Amit Saha
> On 28 Nov 2020, at 8:14 pm, b.ca...@pobox.com wrote: > > Do you see a forward or reverse DNS lookup being made? > > Can you provide a standalone program which demonstrates this behaviour? > > I am wondering if either (a) something is logging when the connection is > terminated, or (b) a

[go-nuts] Trying to understand HTTP connection pooling behaviour - new DNS lookup

2020-11-27 Thread Amit Saha
Hi, it seems that the http client automatically performs a DNS lookup when an existing connection is terminated by the server. I simulated it via changing the IP address in /etc/hosts. Can someone point me to the code where this logic is checked? I am looking at

[go-nuts] Clarification regarding RoundTripper's guidance on Response

2020-11-25 Thread Amit Saha
Hi all, I am wondering whether the RoundTripper’s documentation on what can be done with the Response obtained needs further clarification as to is it ok or not to modify the response object? In addition is it safe to consume the Response from another groutine after/when the RoundTripper

Re: [go-nuts] How to detect if transport connection break

2020-11-20 Thread Amit Saha
On Sat, 21 Nov 2020, 2:12 am Afriyie Abraham Kwabena, < afriyie.abra...@gmail.com> wrote: > Hi, > > Yes, that is what intend to implement. Can you help with some information > about how > I could implement it. > If possible some libraries or example code. > The standard library's http client as

Re: [go-nuts] How to detect if transport connection break

2020-11-20 Thread Amit Saha
On Fri, 20 Nov 2020, 7:51 pm Afriyie Abraham Kwabena, < afriyie.abra...@gmail.com> wrote: > > Hi, > > My basic understanding of HTTP protocol is that an HTTP client sent > request, get response from the HTTP server and then the connection is > closed. > > My question is how can an HTTP client

[go-nuts] Re: Testing HTTP client timeout behaviour

2020-11-14 Thread Amit Saha
> On 14 Nov 2020, at 10:28 pm, Amit Saha wrote: > > Hi all, I am attempting to write a test for http client timeout behaviour. > Here’s my bad test server: > > func startBadTestHTTPServer() *httptest.Server { > ts := httptest.NewServer(http.HandlerFunc(func(w h

[go-nuts] Testing HTTP client timeout behaviour

2020-11-14 Thread Amit Saha
Hi all, I am attempting to write a test for http client timeout behaviour. Here’s my bad test server: func startBadTestHTTPServer() *httptest.Server { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { time.Sleep(60 * time.Second)

Re: [go-nuts] Running "go test" modifies go.mod & go.sum

2020-11-01 Thread Amit Saha
> On 1 Nov 2020, at 7:22 pm, 'Dan Kortschak' via golang-nuts > wrote: > > You're using go test, with -mod=readonly, but it's running your code > with go run, without -mod=readonly. > > Either you'll need to unconditionally pass -mod=readonly to go run in > the regression_test.go file, or

Re: [go-nuts] Running "go test" modifies go.mod & go.sum

2020-11-01 Thread Amit Saha
On Sun, 1 Nov 2020, 4:07 pm Miki Tebeka, wrote: > Hi, > > I wrote a regexp linter (https://github.com/tebeka/recheck) that's using > golang.org/x/tools/go/analysis. > > To test the tool, I run "go run ./cmd/recheck testdata/ok.go" (using > os/exec). The problem is that after the test, go.mod &

[go-nuts] Context tree inspection/printing

2020-10-22 Thread Amit Saha
Hi all, I have been exploring contexts recently and I am curious does anyone know of/have written a tool to analyse packages and print context trees? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop

Re: [go-nuts] Table driven tests and error/output testing

2020-10-22 Thread Amit Saha
sting, thank you. I will have a look. > > On Tue, 20 Oct 2020 at 05:02, Amit Saha <mailto:amitsaha...@gmail.com>> wrote: > Hi all, Consider the following test configuration: > > > func TestHandleCommand(t *testing.T) { > > type expectedResult struct { >

Re: [go-nuts] Table driven tests and error/output testing

2020-10-20 Thread Amit Saha
> On 20 Oct 2020, at 4:13 pm, Tamás Gulácsi wrote: > > Use bytes.Buffer or strings.Builder directly - no need for the bufio.Writer. > bufio.Writer only speeds up writing by calling the underlying Writer less, > with bigger slices. > Here you Write into a memory, just as bufio.Writer. > >

Re: [go-nuts] Positional arguments and flag package

2020-10-19 Thread Amit Saha
re elements can be every >> character string >> >> BR, >> Roland >> >> Am Fr., 9. Okt. 2020 um 07:10 Uhr schrieb Amit Saha : >>> >>> Hi all, I realize that the flag package stops parsing os.Args[] once it >>> finds a non "-&

  1   2   >