[go-nuts] go-embed results in http 404

2023-09-02 Thread Sankar
I have the following go code where I try to embed a html file from a public 
directory and running into HTTP 404.  What am I doing wrong ? Relevant code 
snippet:


// go:embed public
var public embed.FS

func main() {
// cd to the public directory
publicFS, err := fs.Sub(public, "public")
if err != nil {
log.Fatal(err)
}
http.Handle("/embedded/", http.FileServer(http.FS(publicFS)))

http.Handle("/public/",
http.StripPrefix("/public/", http.FileServer(http.Dir("public"

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

The entire golang file and the html file are available 
in https://github.com/psankar/static-serve

I have tried adding even a `http.StripPrefix` for the `/embedded/` path 
also but even that does not help. Any pointers on what I am doing wrong ?

-- 
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/bd659773-029a-4a39-b845-d10983654597n%40googlegroups.com.


[go-nuts] gRPC for web applications with millions of users

2022-12-02 Thread Sankar
Hi,

I have used gRPC for some simple applications, where the server is in 
Golang and the client is also another golang application. I have primarily 
worked in the backend and have done a lot of gRPC communication among the 
backend services using the likes of gRPC streams and golang.

Now for the first time, I am trying to implement a web application. The 
client apps will be done in react-native. So I was thinking of using the 
javascript gen code for the client libraries.

However I read from some blogposts, when I searched for how to use gRPC in 
javascript, I read that gRPC cannot be used for consumer facing 
applications and is only fit for backend applications. I read that grpc 
streaming will not work with Browser based applications.

Also I read that gRPC will not scale if there are millions of user requests 
coming from browsers. I am sure that gRPC can handle a lot of backend 
volume, but I have not used with a lot of parallel connections. 

So I wanted to ask, if gRPC is used by any consumer facing applications, 
where the backend  is done in Go and the front end is done in some form of 
javascript framework, with a few million users.

Any feedback, suggestions, links, etc. on this topic are also welcome.

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/62b922a6-f86c-4960-81d4-d61b86df7f46n%40googlegroups.com.


[go-nuts] Generics question

2022-03-21 Thread Sankar P
I have the following code snippet.

type workloadInterface interface {
*appsV1.Deployment | *appsV1.StatefulSet
}

.
.
.

func (a *adapter) processDepOrSSForSvc(client kubernetes.Interface,
ns, svcName, workloadName, svcVersionType string) {
switch svcVersionType {
case serviceDeployment:
dep, err := client.AppsV1().Deployments(ns).Get(
context.Background(), workloadName, v1.GetOptions{})
if err != nil {
log.Errorf("Deployment fetch failed: %v", err)
return
}
processWorkload[*appsV1.Deployment](dep)  // <- generics 
call

case serviceStatefulSet:
ss, err := client.AppsV1().StatefulSets(ns).Get(
context.Background(), workloadName, v1.GetOptions{})
if err != nil {
log.Errorf("Statefulset fetch failed: %v", err)
return
}
processWorkload[*appsV1.StatefulSet](ss)   // <-- generics 
call

.
.
.

func processWorkload[V workloadInterface](w V)  {  //
<--generic function
log.Debugf("Namespace: %s Service: %s Deployment: %s",
ns, t.ServiceName, w.Name)  <- Error here


What am I doing wrong ? I am trying to use generics where the object could
be either a `Deployment` or `StatefulSet`.

If I compile, I get an error like:

internal/telegraf-adapter/service-details.go:143:24: w.Name undefined
(type V has no field or method Name)
internal/telegraf-adapter/service-details.go:144:23: w.Name undefined
(type V has no field or method Name)
internal/telegraf-adapter/service-details.go:146:11: w.Annotations
undefined (type V has no field or method Annotations)

Name and Annotations are methods available in both the Deployment and the
StatefulSet structs.

Thanks.

-- 
Sankar P
http://psankar.blogspot.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/CAMSEaH5%2Bv%3DbTbThB407vnUb_81qRwkon36eCzKW-Q%3DbZ-YgcAg%40mail.gmail.com.


[go-nuts] grpc and golang struct tags

2021-11-27 Thread Sankar
Hi

I have a database that has a column `2xxCode`. This database is part of a 
legacy system and I cannot make changes to this, as there are multiple 
applications that depend on this, and some of the applications are 
unchangeable.

Now I want to create a new gRPC server in golang that has to interact with 
the data stored in this database.

Since golang variable names cannot begin with a number, I need create a 
`.proto` file which should generate a golang struct member like:

type mystruct {
TwoxxCode `db:"2xxCode"`
}

from my .proto file. But I could not find out how to generate a golang 
struct from a .proto file, with adding custom tags to the struct. On 
searching, I found https://github.com/golang/protobuf/issues/52 and the 
second comment on the issue seems very strongly worded as if this would 
never happen in protobuf. Also, the bug seems open for a long time.

How have others solved this problem to add custom tags to proto generated 
golang structs ? Are there any best-known-methods for this ? There were a 
couple of scripts mentioned in the comments, but I am not sure what to 
pick. Any recommendations ?

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/239e2f6a-09f7-4e89-a921-ec3fead637c7n%40googlegroups.com.


[go-nuts] go mod vendor without updating packages

2021-05-11 Thread Sankar
Hi,

I have some packages with some versions in my `go.mod` including some 
indirect dependencies that are needed by some of my direct dependencies. In 
this, there is a particular version of grpc that I want to use (and not the 
latest).

I add the specific version of grpc I want by:

go mod edit -require=google.golang.org/grpc@v1.29.1

which correctly updates the `go.mod` file. But when I run the `go mod 
vendor` next, this grpc line gets deleted and the latest of grpc is fetched 
again. How do I enforce and vendor a particular version of an indirect 
dependency ?

-- 
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/179f20f2-a4ae-4745-a48d-eb1ff7f8d3can%40googlegroups.com.


Re: [go-nuts] Go Documentation for private github projects

2021-02-21 Thread Sankar
On Saturday, 20 February 2021 at 15:58:30 UTC+5:30 mb0 wrote:

> Hi, 
> this January a fork of gddo was was announced to this list. Take a look 
> https://godocs.io/ 
>

Thanks a lot. This seems handy.
 

>
> Best regards 
>
> On 20.02.21 08:13, Sankar P wrote: 
> > Hi 
> > 
> > We have a bunch of private repos in github with Go sources. We want to 
> > see the documentation for these repository sources in an easy to click 
> URL. 
> > 
> > We are comfortable with deploying a FOSS binary/service, which can 
> > authenticate to github as a dedicated user and get the repositories. Now 
> > I want to see the docs for this. What is the way to achieve this ? 
> > 
> > In the past, I have used `godoc.org/github.com/ 
> > <http://godoc.org/github.com/>/ ` for public repos. I 
> > want to do similarly for private repos with the `godoc.org 
> > <http://godoc.org>` replaced by our custom domain. 
> > 
> > https://github.com/golang/gddo <https://github.com/golang/gddo> project 
> > is archived and I do not know what is the recommended way now. 
> > 
> > Also, we are in GCP and so if there is some easy hack to get this 
> > deployed in GCP via a single click or some such, that will also be good. 
> > Any pointers ? 
> > 
> > -- 
> > Sankar P 
> > http://psankar.blogspot.com <http://psankar.blogspot.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...@googlegroups.com 
> > <mailto:golang-nuts...@googlegroups.com>. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/golang-nuts/CAMSEaH6OiuqY4Gx_pfbReBDE3JbdQNnUK8sovg_Q33ma45-9zQ%40mail.gmail.com
>  
> > <
> https://groups.google.com/d/msgid/golang-nuts/CAMSEaH6OiuqY4Gx_pfbReBDE3JbdQNnUK8sovg_Q33ma45-9zQ%40mail.gmail.com?utm_medium=email_source=footer>.
>  
>
>

-- 
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/c1d9df2c-7380-4474-951b-d3660f99c208n%40googlegroups.com.


[go-nuts] Go Documentation for private github projects

2021-02-19 Thread Sankar P
Hi

We have a bunch of private repos in github with Go sources. We want to see
the documentation for these repository sources in an easy to click URL.

We are comfortable with deploying a FOSS binary/service, which can
authenticate to github as a dedicated user and get the repositories. Now I
want to see the docs for this. What is the way to achieve this ?

In the past, I have used `godoc.org/github.com// ` for
public repos. I want to do similarly for private repos with the `godoc.org`
replaced by our custom domain.

https://github.com/golang/gddo project is archived and I do not know what
is the recommended way now.

Also, we are in GCP and so if there is some easy hack to get this deployed
in GCP via a single click or some such, that will also be good. Any
pointers ?

-- 
Sankar P
http://psankar.blogspot.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/CAMSEaH6OiuqY4Gx_pfbReBDE3JbdQNnUK8sovg_Q33ma45-9zQ%40mail.gmail.com.


Re: [go-nuts] Run a goroutine until a channel receives a message

2021-01-13 Thread Sankar P
>
> if `ws.Read` returns after a reasonable timeout, you can perform a
> non-blocking receive on the quit channel to see if it has been
> closed/something has been sent to it:
>
> select {
> case <-quit:
> break
> default:
> // Nothing to do here
> }
>
> out, err := ws.Read()
> /* more stuff in the loop */
>

This is brilliant. I feel bad that I did not think of this myself :-)
Thanks.


>
> Another approach would be to use a websocket library that supports
> passing a context to the Read method (not sure if any of those exists).
> For my usual go-to websocket library (github.com/gorilla/websocket), I
> usually set a read deadline on the connection in cases like this and
> more or less do the nonblocking read as above.
>

Yes, I too use the gorilla websocket library only. I have not touched the
"context" related code as it was not part of the initial release and I
never got around to understanding it. Thanks for the pointer. I will see if
that would help me.

Sankar

-- 
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/CAMSEaH67s6nuN7Bnnu4Vz%3DB6YgNyxC%2BcK%2BiVvs9rfyTDwWA4YQ%40mail.gmail.com.


[go-nuts] Run a goroutine until a channel receives a message

2021-01-13 Thread Sankar
I have a function that must be executed as a go routine infinitely until a 
message comes in a channel. For example:

func readWebSocket(ws *websocket.socket, quit chan bool) {
  for {
 out, err =  ws.Read()
 log.Println(out, err)
  }
}

Now I call this above function as a goroutine from main such as:

go readWebSocket(ws, quit)

where I want the for loop to go on until the `quit` channel receives a 
message. The "select" loop seem to work only on multiple channels and not 
on a channel + some looping code.

One alternative that I could think of was to create a second goroutine 
(third if you include main) to which this readWebSocket can send the output 
of "ws.Read" and the select loop can be run there with two channels (the 
quit channel and the new channel which gets the "ws.Read" output) but that 
would leak this reader go-routine infinitely or makes the code more complex.

How to handle this situation gracefully in go channels, where I want a go 
routine to run until a channel gets a message ?

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/32f04de0-4684-40eb-9b1b-8a9a7ff80602n%40googlegroups.com.


Re: [go-nuts] Re: go modules and local packages

2020-08-09 Thread Sankar P
> I had the same situation and this worked perfectly:
>
> replace mylib => ../mylib
>
> If it doesn't - check paths, name of the "mylib" module, etc

Thanks. It worked. I strongly feel like I tried the same yesterday and
it didn't work, but probably mis-typed the name in the module.

-- 
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/CAMSEaH5Fmb7ZwXL2Yttkg1nyj88i%3DNx6V6xhcjyxkRibTB3MKw%40mail.gmail.com.


Re: [go-nuts] go modules and local packages

2020-08-08 Thread Sankar P
> Then why are they in a monorepo?
>
> AFAIK monorepos for strictly controlled dependenies and easier refactorings.
>
> If two part needs different versions for something common, then they should 
> live and evolve  separately.

This is a subset of a larger mono-repo. This repo has sources for
about 40 other services(sources for the binaries) and libraries, in
different languages. All our sources are kept in a single monolithic
repository (like Google, in some sense).

So should I setup some kind of a private modules repository (like
private npm repositories for js or pypi for python) where the library
source archives can be saved !? Is there no other way to do this for
multi-module repositories ?

-- 
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/CAMSEaH5UFqS8dqrSkkr0j82aBjHQGDhDOBAsvgEnVp5E5pm4mg%40mail.gmail.com.


Re: [go-nuts] go modules and local packages

2020-08-08 Thread Sankar P
> Use one go.mod pee repo.

That won't be possible. It is a monolithic repo. svc1 and svc2 may
need two different versions of a common dependency.

-- 
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/CAMSEaH5GJfJ0RgTuo1Gi7sOQ_y2K87qgMvO6qkwZrHt1HdyXmA%40mail.gmail.com.


Re: [go-nuts] go modules and local packages

2020-08-08 Thread Sankar P
> You could try moving mylib to your $GOPATH/src/, and
> import "mylib"
> in the services.

I tried that but could not get `go run cmd/svc1.go` from trying to
checkout a non-existent url (for the `mylib`). Can you share the
contents of the `go.mod` file for svc1 and mylib ?

-- 
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/CAMSEaH5i%2BfYW5keD%3DGBevDWdU7oJ1fGsCsoi%2Bm94xruOKO4cdA%40mail.gmail.com.


[go-nuts] go modules and local packages

2020-08-08 Thread Sankar
Hi

I have a monolithic source repository that is NOT in git, mercurial etc.

The directory structure is:

root
|
|--- mylib
| | --- mylib.go
| | --- go.mod
|--- svc1
|   | --- go.mod
|   | --- cmd
| |  svc1.go
|--- svc2
|   | --- go.mod
|   | --- cmd
| |  svc2.go

Here there is a `mylib` which is a common library. `svc1` and `svc2` are 
two golang http servers that come with their own `go.mod` files. Now I want 
to import the `mylib` in the `svc1` and `svc2` sources and the go.mod files.

Can someone tell me how to achieve this ? I can modify the go.mod of 
`mylib` to anything but cannot publish the sources to a VCS.

I tried adding the following in the go.mod files of svc1 and svc2 but it 
did not work.
replace (
my.lib latest => ../mylib latest
)

Any other suggestions to get this working ? 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/3f4c0e55-d7c1-493a-b08b-dd2d05124447n%40googlegroups.com.


Re: [go-nuts] Re: RFC Package structuring

2020-02-29 Thread Sankar P
ஞாயி., 1 மார்., 2020, முற்பகல் 4:17 அன்று, hartzell 
எழுதியது:

> On Saturday, February 29, 2020 at 10:03:34 AM UTC-8, Sankar wrote:
>>
>> I am starting a new project (say `hello`) and I am totally confused about
>> what package structure to use.  [...]
>>
>
> You might find the project-layout notes from the golang-standards GitHub
> organization (which seems to be a one-person org) useful:
> https://github.com/golang-standards/project-layout
>

Yes, I did check that. But that link has files for only one single
executable. I am looking for a monolithic repository with multiple
executables and multiple libraries.


>
> It has some good ideas and links to other discussions and resources.
>
> I'd avoid hard coding any knowledge of where the tree's checked out (I
> often clone things into ~/tmp to monkey with them).
>

Yes, I too want this only. But how to get vendor and dependents working in
this case is what is unclear to me.


>
> g.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/s062Xbtb7ys/unsubscribe.
> To unsubscribe from this group and all its topics, 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/09bb6e93-acd7-4fcd-8178-fb99a2e56028%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/09bb6e93-acd7-4fcd-8178-fb99a2e56028%40googlegroups.com?utm_medium=email_source=footer>
> .
>


-- 
Sankar P
http://psankar.blogspot.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/CAMSEaH4MuFwcx1SkAd0pGJw13zRfD4eTzcAps7NWvAbEnejvEA%40mail.gmail.com.


[go-nuts] RFC Package structuring

2020-02-29 Thread Sankar
I am starting a new project (say `hello`) and I am totally confused about 
what package structure to use. 

I am going to go with a monolithic source repository which would be checked 
out under `~/src` directory in the developer machines.

I have three golang binaries available in my project.

1) hello-cli : A tool that would give me a CLI, which will be used from my 
client machines. Say something similar to the docker-cli
2) hello-daemon: A daemon to which the CLI tools will talk to. Say 
something similar to docker-daemon
3) hello-api-server: A HTTP server to which the daemon will talk. Say 
something similar to dockerhub API server.

In addition to these three golang binaries, I may have other things like a 
webui, some static assets, some integration tests etc. in multiple 
languages.

There will be some libraries that will be used by each of the golang 
binaries that will be internal only to the specific binaries and there will 
be some libraries, which will be shared across the three binaries. The 
three binaries may depend on different versions of the libraries.

Now the package structure that I thought was:

[image: Screenshot 2020-02-29 at 11.28.45 PM.png]

Will this be good or should I make any change ? I am not sure if vendoring 
would work fine here as there would be no `github.com/` etc. prefix (or 
even GOPATH) as I want to checkout under a special path (`~/src`).

I have attached the hello.zip file also. Does this package structure work ? 
Or should I do something different ?

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/95932aba-93b5-48c3-836b-dfdcac373ebb%40googlegroups.com.
<>


[go-nuts] httputil proxy integrity errors on serving hugo/nginx files

2019-12-04 Thread Sankar
I have a Go proxy server which will proxy the incoming requests to a 
different nginx service, where a bunch of static files generated from hugo 
are deployed. The Go proxy server code is:

```
func (w http.ResponseWriter, r *http.Request) {
proxy := httputil.NewSingleHostReverseProxy(target)
proxy.Transport = debug.Transport{} // Set some Debug TCP options here
proxy.ServeHTTP(w, r)
}
```
The debug.Transport is created like below:

```
type Transport struct {
Transport http.RoundTripper
}

func (d Transport) RoundTrip(r *http.Request) (*http.Response, error) {
fmt.Println(r.Header)
d.Transport = {
TLSClientConfig: {InsecureSkipVerify: true},
}
return d.Transport.RoundTrip(r)
}
```

In the debug Transport, I am already ignoring the certificate checks for 
TLS configuration.

If I directly access the nginx url where hugo static files are served, then 
the static files are perfectly loaded. The static files are served fine 
even if I access from an nginx-ingress in addition to the nginx. However, 
when the requests are served via the Go proxy, then I get an error in my 
browser:

```
Failed to find a valid digest in the 'integrity' attribute for resource 
'https:///js/main.min.29b0315468c00226fa6f4556a9cebc0ac4fe1ce1457a01b22c0a06b329877383.js'
 
with computed SHA-256 integrity 
'Nk/s9htIgKJ5jeLFxUMWgIQGhxGZBKoEWtWEy2qYtJk='. The resource has been 
blocked.
```


Any idea how I can skip this integerity check in the Go http proxy ? I 
cannot find any TLS Config option for it.

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/58f6f4ad-7753-402c-81f0-c7ff35c7fb84%40googlegroups.com.


[go-nuts] golang multiple go routines reading from a channel and performance implications

2019-11-21 Thread Sankar
We have a setup where we have a producer goroutine pumping in a few 
thousand objects into a channel (Approximately 2k requests per second). 
There are a configurable number of goroutines that work as consumers, 
consuming from this single channel. If none of the consumer threads could 
receive the message, the message gets discarded. Each consumer go routine 
takes about 2 seconds for each work to be completed, by which they will 
come back to read the next item in the channel. The channel is sized such 
that it can hold up to 10,000 messages.

The code is roughly something like:

producer.go:
func produce() {
 ch <- item
}

func consumer() {
 for i:=0; i < NumberOfWorkers; i ++ {
   go func() {
  for _, item := range ch {
 // process item
  }
   } ()
 }
}

With this above setup, we are seeing about 40% of our messages getting 
dropped.

So my questions are:

1) In such a high velocity incoming data, will this above design work ? 
(Producer, Consumer Worker Threads)
2) We did not go for an external middleware for saving the message and 
processing data later, as we are concerned about latency for now.
3) Are channels bad for such an approach ? Are there any other alternate 
performant mechanism to achieve this in the go way ?
4) Are there any sample FOSS projects that we can refer to see such 
performant code ? Any other book, tutorial, video or some such for these 
high performance Golang application development guidelines ?

I am planning to do some profiling of our system to see where the 
performance is getting dropped, but before that I wanted to ask here, in 
case there are any best-known-methods that I am missing out on. 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/f8b5d9fb-d9b7-44b8-bc50-70dcb5f10cd0%40googlegroups.com.


[go-nuts] golang tool for splitting long lines

2019-11-14 Thread Sankar
Hi

In Javascript world I have this handy tool Prettier which will 
automatically, reproducibly break long lines of code into multiple lines 
(and also merge parameters into a single line if some elements are 
removed). 

Are there similar tools available for Golang ? Either as a standalone 
program or as VSCode/Goland plugins.

>From https://github.com/golang/go/issues/11915 I believe that go team may 
not address it as natively as gofmt/goimports. But are there any other 
hacks/tools that people already use to break long lines ? 

Thanks.

Sankar

-- 
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/063ade8f-ffd2-4481-891a-c8fe7cb480ef%40googlegroups.com.


[go-nuts] .editorconfig for golang projects & github pr automated gofmt checks

2019-07-01 Thread Sankar
Hi

We use github for our sources. Developers are free to choose their IDEs and 
tools. Sometimes, people end up committing sources using spaces instead of 
tabs, etc. Not all developers do goimports/gofmt on save. So, we want to 
automate this process. However, instead of adding git pre-commit hooks, we 
want to have this done only when people raise a github PR. Have any of you 
done this in your project and shared your experience in a blog / writeup ? 
Please let us know. Googling would still be done for this, but wanted to 
ask in this list also.

Another somewhat related query is, we are also considering adding a 
.editorconfig for our Golang projects. Are there any standard .editorconfig 
settings for *.go that you use ?

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/e27fe1f7-402c-4a6a-8f65-a7536c052636%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] The go way to compare values against an enum

2019-04-15 Thread Sankar P
Whoa. I did not realise this. Thanks for the help.

திங்., 15 ஏப்., 2019, பிற்பகல் 9:54 அன்று, Marvin Renich 
எழுதியது:

> Roger and Jan have given you good answers, but I would like to comment
> on another aspect of your code.
>
> * Sankar  [190415 04:53]:
> > type weekday string
> >
> > const (
> >   Monday weekday = "Monday"
> >   Tuesday = "Tuesday"
> >   .
> >   .
> >   .
> > )
>
> Note that the type of Monday will be weekday, while the type of Tuesday
> will be untyped string.  The spec allows omitting the expression list
> after the first const declaration in a parenthesized list, but if you
> omit the type, but not the expression list, the type is implied by the
> expression, not by the type of the previous const.
>
> ...Marvin
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/cs1DE0jOOfA/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Casting across types

2019-04-15 Thread Sankar P
Thanks :)

திங்., 15 ஏப்., 2019, பிற்பகல் 4:20 அன்று, roger peppe 
எழுதியது:

> The dynamic type conversion needs to specify the exact type that was put
> into the interface (B in this case).
> You can convert it back to A afterwards:
> https://play.golang.org/p/jBRtR_8RloC
>
> On Mon, 15 Apr 2019 at 11:32, Sankar P  wrote:
>
>> Playground url: https://play.golang.org/p/tDT7xCJJ_XN
>>
>> திங்., 15 ஏப்., 2019, பிற்பகல் 4:01 அன்று, Sankar <
>> sankar.curios...@gmail.com> எழுதியது:
>>
>>> I have the following go code:
>>>
>>> ```
>>> type A map[string]interface{}
>>> type B map[string]interface{}
>>>
>>> func f(a A) {
>>> fmt.Println(a)
>>> }
>>>
>>> func main() {
>>> var b B
>>> b = make(map[string]interface{})
>>> i := interface{}(b)
>>> f(i.(A))
>>> }
>>> ```
>>>
>>> This code panics when I try to convert the B instance to type A. What is
>>> the right way to do the cast here ?
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "golang-nuts" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/golang-nuts/f3jarN-BgC0/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> golang-nuts+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>> --
>> Sankar P
>> http://psankar.blogspot.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.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Casting across types

2019-04-15 Thread Sankar P
Playground url: https://play.golang.org/p/tDT7xCJJ_XN

திங்., 15 ஏப்., 2019, பிற்பகல் 4:01 அன்று, Sankar <
sankar.curios...@gmail.com> எழுதியது:

> I have the following go code:
>
> ```
> type A map[string]interface{}
> type B map[string]interface{}
>
> func f(a A) {
> fmt.Println(a)
> }
>
> func main() {
> var b B
> b = make(map[string]interface{})
> i := interface{}(b)
> f(i.(A))
> }
> ```
>
> This code panics when I try to convert the B instance to type A. What is
> the right way to do the cast here ?
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/f3jarN-BgC0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Casting across types

2019-04-15 Thread Sankar
I have the following go code:

```
type A map[string]interface{}
type B map[string]interface{}

func f(a A) {
fmt.Println(a)
}

func main() {
var b B
b = make(map[string]interface{})
i := interface{}(b)
f(i.(A))
}
```

This code panics when I try to convert the B instance to type A. What is 
the right way to do the cast here ?

-- 
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.


Re: [go-nuts] The go way to compare values against an enum

2019-04-15 Thread Sankar P
thanks guys.

திங்., 15 ஏப்., 2019, பிற்பகல் 2:30 அன்று, roger peppe 
எழுதியது:

> Go doesn't have enum types. For any given type, even if there are
> constants of that type, that doesn't mean that those are all the valid
> values of that type. For that reason, Go doesn't provide any specific
> functionality to do what you'd like.
>
> I'd suggest creating a map that holds all the valid weekday names:
>
> var weekdays = map[string]bool{
> "Monday": true,
> "Tuesday": true,
> ... etc
> }
>
> func IsValidWeekday(s string) bool {
> return weekdays[s]
> }
>
> There might not be any particular advantage to creating a specific weekday
> type in this case.
> That might be different if you were going to use an integer representation
> (as the time package does <https://golang.org/pkg/time/#Weekday>, for
> example).
>
> Hope this helps,
>   rog.
>
>
> On Mon, 15 Apr 2019 at 09:52, Sankar  wrote:
>
>> Hi,
>>
>> I have the following Go type.
>>
>> ```
>> type weekday string
>>
>> const (
>>   Monday weekday = "Monday"
>>   Tuesday = "Tuesday"
>>   .
>>   .
>>   .
>> )
>> ```
>>
>> Now I have a function that receives a string parameter and I want to
>> evaluate if it s a valid weekday or not. Say:
>>
>> ```
>> func handler(w http.ResponseWriter, r *http.Request) {
>>
>> // Parse req.body and get a day string
>>
>> day := "Tuesday" // Valid day
>> day := "tuesday" // Invalid day
>> day := "123819283" // Invalid day
>>
>> }
>> ```
>>
>> I want to evaluate if the string variable `day` is one of the valid
>> permitted values for the [Ww]eekday custom type. What is the recommended /
>> right go way of doing this ?
>>
>> 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.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] serverless frameworks

2019-01-22 Thread Sankar
Hi

Now that Google has released support for Cloud Functions, I am curios to 
know are there any frameworks that the community is already using for 
standardizing the serverless deployments. A few things that I would be 
happy to have are:

1) Single command deploy of multiple functions based on whatever is dirty
2) Easy offline testing (including any middleware such as pubsub)
3) Standard integration for things like observability/tracing, logging, etc.
4) Support for environment variables (for secure things like API Keys etc.)

I don't mind even if a framework offers these for only one cloud provider 
(GCP preferred but AWS is also fine).

Any experience from gophers here ?

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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: go src organization question

2018-10-21 Thread Sankar P
I am yet to go through your mail in detail. But I will answer the primary
question first. I have a monolithic repository which contains all my go
backend related code in a single project. I have about 8 packages that are
internally defined inside my repo, and I do not need any version management
for any of them. All of these are very specific to my project and some are
just structs.

I have about 5 third party packages which I depend on and some of them are
quite popular, like the pq driver for postgres, dgrijalva/jwt-go, etc., So
over all about a dozen packages are dependencies in total.

ஞாயி., 21 அக்., 2018, பிற்பகல் 11:32 அன்று, 
எழுதியது:

> Hi Sankar,
>
> How many repos are you directly modifying?
>
> Most projects are likely following the simplest approach of using a single
> module per repository, which typically would mean creating one go.mod file
> located in the root directory of each repository. (The official modules
> proposal predicts that is what most projects will do:
> https://go.googlesource.com/proposal/+/master/design/24301-versioned-go.md
> ).
>
> Separately, I believe you are correct that relative import paths are not
> supported with modules. See this FAQ on the modules wiki:
> https://github.com/golang/go/wiki/Modules#do-modules-work-with-relative-imports-like-import-subdir
> and the related issue
> https://github.com/golang/go/issues/26645#issuecomment-408572701, which
> includes this comment:
>
>> In modules, there finally is a name for the subdirectory. If the
> parent directory says "module m" then the subdirectory is imported as
> "m/subdir", no longer "./subdir".
>
> If you end up with one module per repo, a related question would be how
> many modules are you editing at roughly the same time? If that is part of
> your concern or question, then there are a few different options there.
> I'll include a few pointers here for things to review and consider, but
> then after looking over those, you might want to circle back here with
> additional questions or comments on your use case.
>
> For editing multiple modules at the same time, one approach is to use the
> 'replace' directive to point to local copies. You can read a bit more about
> that in this FAQ on the modules wiki:
>   "FAQ: When should I use the replace directive?"
>
> https://github.com/golang/go/wiki/Modules#when-should-i-use-the-replace-directive
>
> A related but more automated approach is github.com/rogpeppe/gohack,
> which is a new community tool to automate and simplify 'replace' and
> multi-module workflows, including allowing you to easily modify one of your
> dependencies. For example, 'gohack example.com/some/dependency'
> automatically clones the appropriate repository and adds the necessary
> replace directives to your 'go.mod' so that you can edit that dependency
> and build using those edits, all locally and without requiring you to
> commit anything yet. You can read more about 'gohack' at the repo, or you
> can also see a worked example of using 'gohack' at the 'Go Modules by
> Example' site here:
> https://github.com/go-modules-by-example/index/blob/master/011_using_gohack/README.md
>
> There are several more options as well for multi-module workspaces,
> including the core go tooling seems to have been built to make it possible
> to build more specific tools on top. There's an overview of several of the
> options in the following thread, including possibly using commit hooks, or
> using pre-release semver tags, etc., as well as some pointers to related
> discussion issues in the tracker:
>   https://groups.google.com/d/msg/golang-nuts/0KQ4ZuSpzy8/5m4Ek7q2BgAJ
>
> Sorry that is probably not 100% answering your question, but perhaps you
> can say a bit more about your specifics, which then likely will trigger
> some more specific comments from this list.
>
> --thepudds
>
> On Sunday, October 21, 2018 at 12:31:34 PM UTC-4, Sankar wrote:
>>
>> Hi,
>>
>> We were using go 1.7 until recently and now want to switch to 1.11 and
>> start using go modules.
>>
>> Currently our source organization is as follows:
>>
>> ~/go/src/gitlab.com/example/
>>|
>>|
>>example/
>> |
>> |
>> |api/
>> |   |
>> |   main.go (imports library1,
>> library2 and some 3rd party libs)
>> |library1/
>> |

[go-nuts] go src organization question

2018-10-21 Thread Sankar
Hi,

We were using go 1.7 until recently and now want to switch to 1.11 and 
start using go modules.

Currently our source organization is as follows:

~/go/src/gitlab.com/example/
   |
   |
   example/
|
|
|api/
|   |
|   main.go (imports library1, 
library2 and some 3rd party libs)
|library1/
|   |
|   lib1.go
|library2/
|  |
|  lib2.go

In our main.go, We were importing packages like:

```
"gitlab.com/example/example/library1"
"gitlab.com/example/example/library2"
"gitHUB.com/3rdpary/library"
```

We actually wanted to import library1 and library2 via relative path 
("../library[12]") but since the go compiler did not support relative 
imports then, we used the absolute imports. We did not use any dependency 
management tool (like dep, glide etc.).

The libraries that we write (library1 and library2) need not be versioned 
and will always be used in a reliable state in our api/main.go

We however need versioning support for our 3rd party libraries.

For such a hybrid requirement, what is the most recommended way to import 
and structure our libraries and the source directories, to work with go 
modules ? I tried reading through https://github.com/golang/go/wiki/Modules 
but I could not find out any recommended way for this. Any help on how I 
can do this ? Do I need to create `cmd` or `src` folders in our git repo ? 
OR do we need to do something else ? Any links for blogposts, tutorials, 
documentation, videos etc. will be helpful. 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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] golang maps; using slice as a key

2018-05-23 Thread Sankar P
Thanks.

2018-05-23 13:55 GMT+05:30 <pierre.cu...@gmail.com>:

> You keep the reference of the loop index that points at the last array.
> Either make a copy of it or use a slice of arrays.
>
> https://play.golang.org/p/WcOHQ_wIKjx
> https://play.golang.org/p/CToFC9w88M7
>
>
> Le mercredi 23 mai 2018 09:59:53 UTC+2, Sankar a écrit :
>>
>> I extracted the confusing part alone, when appending to an array, the
>> items are different than the resultant array into a separate go program.
>>
>> The Playground URL is: https://play.golang.org/p/BJM0H_rYNdb
>>
>> If someone can explain the output I would be thankful. It feels like a
>> bug to me, but I am sure that I am only misunderstanding and it may not be
>> a bug.
>>
>> Thanks.
>>
>>
>> 2018-05-23 11:45 GMT+05:30 Sankar P <sankar.c...@gmail.com>:
>>
>>> Use an array instead of a slice. An array has a fixed size and can be
>>>> used as a key to a map
>>>>
>>>> https://play.golang.org/p/xxxmrwpx08A
>>>>
>>>
>>> This seem to not work. The arr is returning only duplicate elements in
>>> your playground url.
>>>
>>> For example:
>>>
>>>var arr [][]int
>>> for mem := range m {
>>> fmt.Println("Appending: ", mem[:])
>>> arr = append(arr, mem[:])
>>> }
>>> fmt.Println("Final arr is:", arr)
>>>
>>> the output is:
>>>
>>> Appending:  [-1 0 1]
>>> Appending:  [-1 -1 2]
>>> Final arr is: [[-1 -1 2] [-1 -1 2]]
>>>
>>> I am not really able to understand why the above code works so. The
>>> "Appending" and the "Final arr" statements have different values.
>>>
>>> --
>>> Sankar P
>>> http://psankar.blogspot.com
>>>
>>
>>
>>
>> --
>> Sankar P
>> http://psankar.blogspot.com
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/fcBDb2wjtac/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] golang maps; using slice as a key

2018-05-23 Thread Sankar P
I extracted the confusing part alone, when appending to an array, the items
are different than the resultant array into a separate go program.

The Playground URL is: https://play.golang.org/p/BJM0H_rYNdb

If someone can explain the output I would be thankful. It feels like a bug
to me, but I am sure that I am only misunderstanding and it may not be a
bug.

Thanks.


2018-05-23 11:45 GMT+05:30 Sankar P <sankar.curios...@gmail.com>:

> Use an array instead of a slice. An array has a fixed size and can be used
>> as a key to a map
>>
>> https://play.golang.org/p/xxxmrwpx08A
>>
>
> This seem to not work. The arr is returning only duplicate elements in
> your playground url.
>
> For example:
>
>var arr [][]int
> for mem := range m {
> fmt.Println("Appending: ", mem[:])
> arr = append(arr, mem[:])
> }
> fmt.Println("Final arr is:", arr)
>
> the output is:
>
> Appending:  [-1 0 1]
> Appending:  [-1 -1 2]
> Final arr is: [[-1 -1 2] [-1 -1 2]]
>
> I am not really able to understand why the above code works so. The
> "Appending" and the "Final arr" statements have different values.
>
> --
> Sankar P
> http://psankar.blogspot.com
>



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] golang maps; using slice as a key

2018-05-23 Thread Sankar P
https://play.golang.org/p/dqp7po8Tg_4 is a working solution and it takes
only O(n^2), if you are curios. Your way of creating a numMem is also nice.
Thanks.

2018-05-23 12:55 GMT+05:30 Karan Chaudhary <fghj...@gmail.com>:

> One other simpler (and not so elegant) solution is to use separate set for
> each element.
>
> https://play.golang.org/p/9ZSRfAyOX4-
>
> @Bakul's solution sounds good but haven't tried to understand it clearly.
>
>
>
>
> On Wednesday, 23 May 2018 11:46:15 UTC+5:30, Sankar wrote:
>>
>> Use an array instead of a slice. An array has a fixed size and can be
>>> used as a key to a map
>>>
>>> https://play.golang.org/p/xxxmrwpx08A
>>>
>>
>> This seem to not work. The arr is returning only duplicate elements in
>> your playground url.
>>
>> For example:
>>
>>var arr [][]int
>> for mem := range m {
>> fmt.Println("Appending: ", mem[:])
>> arr = append(arr, mem[:])
>> }
>> fmt.Println("Final arr is:", arr)
>>
>> the output is:
>>
>> Appending:  [-1 0 1]
>> Appending:  [-1 -1 2]
>> Final arr is: [[-1 -1 2] [-1 -1 2]]
>>
>> I am not really able to understand why the above code works so. The
>> "Appending" and the "Final arr" statements have different values.
>>
>> --
>> Sankar P
>> http://psankar.blogspot.com
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/fcBDb2wjtac/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] golang maps; using slice as a key

2018-05-23 Thread Sankar P
>
> Use an array instead of a slice. An array has a fixed size and can be used
> as a key to a map
>
> https://play.golang.org/p/xxxmrwpx08A
>

This seem to not work. The arr is returning only duplicate elements in your
playground url.

For example:

   var arr [][]int
for mem := range m {
fmt.Println("Appending: ", mem[:])
arr = append(arr, mem[:])
}
fmt.Println("Final arr is:", arr)

the output is:

Appending:  [-1 0 1]
Appending:  [-1 -1 2]
Final arr is: [[-1 -1 2] [-1 -1 2]]

I am not really able to understand why the above code works so. The
"Appending" and the "Final arr" statements have different values.

-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] golang maps; using slice as a key

2018-05-22 Thread Sankar
Is there a way to use a slice as a key to a map ? If I try, I get a 
compilation error: `invalid map key type`. 

I tried creating a custom type, which contains an array as the element. 
However, I could not find out what method to implement for my custom 
type(such as: func (i *myType) Equal(j *myType) bool ) that would make the 
equality operator call this function. 

An example program, where I needed to use a slice/array as the key of a map 
is also available at: https://play.golang.org/p/kXwAaHckL76 

Is there a way (or alternate solutions) to use a slice as the map key ? 

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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: RFC - Review request for a project done in Golang

2018-05-15 Thread Sankar P
In case someone is curios, I did refactor the code a lot more, to bring
down the gocyclo complexity from 23 to 11. I feel that this should be in a
better shape now. Thanks everyone for the comments. Let me know if you
still find any scope for optimisation or cleanup.

I would add some test cases too after I feel satisfied with the code.

2018-05-14 20:54 GMT+05:30 Sankar P <sankar.curios...@gmail.com>:

> 2018-05-14 20:39 GMT+05:30 <matthewju...@gmail.com>:
>
>> They might have been looking for something like this:
>>
>> github.com/psankar/network-monitor
>> package monitor code files
>> cmd/
>> minion/
>> package main code files
>> server/
>> package main code files
>>
>
> The reviewer mentioned that the code was not easy to work with and
> unstructured. So I am almost sure that it has nothing to do with the
> package structure. Your mail however gave me an idea about using gocyclo
> and it found a score of 23 for the code, which is bordering on bad code.
> May be I could restructure into different functions a bit. Thanks.
>
>
>>
>> In a code review I would mention the use of packages as not being ideal,
>> but that’s just my opinion. You seem able to write Go code, but there
>> aren’t tests in this solution. How did you verify it?
>>
>
> I had some tests but I did not include them in the github repo. They were
> not very exhaustive, but just covered the basic cases, through a script
> that will add/remove files and contents.
>
>
>> Maybe you passed but there was a better candidate?
>>
>
> Could be.
>
>
>>
>> Matt
>>
>> On Monday, May 14, 2018 at 6:35:23 AM UTC-5, Sankar wrote:
>>>
>>> Hi
>>>
>>> I was recently asked in an interview to write a golang program for a
>>> problem that involves working with a million nodes. I did write a program
>>> that solved the problem statement. However, I was told that the solution
>>> was "poorly structured", but I did not get any detailed review comments
>>> though.
>>>
>>> So, I recreated the solution in github and wanted to know if anyone
>>> could give some review comments as to what you see as bad things in the
>>> code.
>>>
>>> The problem statement, code and the instructions are at:
>>> https://github.com/psankar/network-monitor
>>>
>>> I personally felt that the code (written in about 6 hours for the
>>> interview) is good and I would've hired anyone writing this, but may be I
>>> am biased because it is written by me. I want to improve my Golang skills
>>> and your review comments would be helpful. Any help ?
>>>
>>> If the golang list is unsuitable for this, you can even email me,
>>> individually, with the review comments.
>>>
>>> Thanks.
>>>
>>> Sankar
>>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "golang-nuts" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>> pic/golang-nuts/SpoC7siQrS8/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> golang-nuts+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Sankar P
> http://psankar.blogspot.com
>



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: RFC - Review request for a project done in Golang

2018-05-14 Thread Sankar P
2018-05-14 20:39 GMT+05:30 <matthewju...@gmail.com>:

> They might have been looking for something like this:
>
> github.com/psankar/network-monitor
> package monitor code files
> cmd/
> minion/
> package main code files
> server/
> package main code files
>

The reviewer mentioned that the code was not easy to work with and
unstructured. So I am almost sure that it has nothing to do with the
package structure. Your mail however gave me an idea about using gocyclo
and it found a score of 23 for the code, which is bordering on bad code.
May be I could restructure into different functions a bit. Thanks.


>
> In a code review I would mention the use of packages as not being ideal,
> but that’s just my opinion. You seem able to write Go code, but there
> aren’t tests in this solution. How did you verify it?
>

I had some tests but I did not include them in the github repo. They were
not very exhaustive, but just covered the basic cases, through a script
that will add/remove files and contents.


> Maybe you passed but there was a better candidate?
>

Could be.


>
> Matt
>
> On Monday, May 14, 2018 at 6:35:23 AM UTC-5, Sankar wrote:
>>
>> Hi
>>
>> I was recently asked in an interview to write a golang program for a
>> problem that involves working with a million nodes. I did write a program
>> that solved the problem statement. However, I was told that the solution
>> was "poorly structured", but I did not get any detailed review comments
>> though.
>>
>> So, I recreated the solution in github and wanted to know if anyone could
>> give some review comments as to what you see as bad things in the code.
>>
>> The problem statement, code and the instructions are at:
>> https://github.com/psankar/network-monitor
>>
>> I personally felt that the code (written in about 6 hours for the
>> interview) is good and I would've hired anyone writing this, but may be I
>> am biased because it is written by me. I want to improve my Golang skills
>> and your review comments would be helpful. Any help ?
>>
>> If the golang list is unsuitable for this, you can even email me,
>> individually, with the review comments.
>>
>> Thanks.
>>
>> Sankar
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/to
> pic/golang-nuts/SpoC7siQrS8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: RFC - Review request for a project done in Golang

2018-05-14 Thread Sankar P
2018-05-14 17:28 GMT+05:30 Tamás Gulácsi <tgulacs...@gmail.com>:

> Minion/minion? For what?
>

So that the minion package structs can be shared between Minion/Minion.go
server and the APIServer.go server.


>
> Also APIServer.go has some goroutine starting loops that are very similar
> - should be a function.
> I'd prefer splitting the HTTP handlers to parser + executor + responder
> (a'la go-kit), clarifying the business logic.
>

I moved the actual network call to the contactMinion function, but as you
said it is probably a good idea to split the handler. Thanks.


>
> Just my 2¢.
>
>
>
> 2018. május 14., hétfő 13:35:23 UTC+2 időpontban Sankar a következőt írta:
>>
>> Hi
>>
>> I was recently asked in an interview to write a golang program for a
>> problem that involves working with a million nodes. I did write a program
>> that solved the problem statement. However, I was told that the solution
>> was "poorly structured", but I did not get any detailed review comments
>> though.
>>
>> So, I recreated the solution in github and wanted to know if anyone could
>> give some review comments as to what you see as bad things in the code.
>>
>> The problem statement, code and the instructions are at:
>> https://github.com/psankar/network-monitor
>>
>> I personally felt that the code (written in about 6 hours for the
>> interview) is good and I would've hired anyone writing this, but may be I
>> am biased because it is written by me. I want to improve my Golang skills
>> and your review comments would be helpful. Any help ?
>>
>> If the golang list is unsuitable for this, you can even email me,
>> individually, with the review comments.
>>
>> Thanks.
>>
>> Sankar
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/SpoC7siQrS8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] RFC - Review request for a project done in Golang

2018-05-14 Thread Sankar
Hi

I was recently asked in an interview to write a golang program for a 
problem that involves working with a million nodes. I did write a program 
that solved the problem statement. However, I was told that the solution 
was "poorly structured", but I did not get any detailed review comments 
though. 

So, I recreated the solution in github and wanted to know if anyone could 
give some review comments as to what you see as bad things in the code.

The problem statement, code and the instructions are 
at: https://github.com/psankar/network-monitor 

I personally felt that the code (written in about 6 hours for the 
interview) is good and I would've hired anyone writing this, but may be I 
am biased because it is written by me. I want to improve my Golang skills 
and your review comments would be helpful. Any help ?

If the golang list is unsuitable for this, you can even email me, 
individually, with the review comments.

Thanks.

Sankar

-- 
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.


Re: [go-nuts] Sorting slice of structs

2018-04-10 Thread Sankar
ah damn. Thanks  everyone :)

On Wednesday, 11 April 2018 00:05:00 UTC+5:30, Jan Mercl wrote:
>
>
> On Tue, Apr 10, 2018 at 8:29 PM Sankar <sankar.c...@gmail.com 
> > wrote:
>
> > Any help on how I can get arr sorted in the above code ?
>
> Just a typo: https://play.golang.org/p/vhbo8OIrh-H
>
> -- 
>
> -j
>

-- 
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.


[go-nuts] Sorting slice of structs

2018-04-10 Thread Sankar
Hi

I have the following code:

type Point struct {
Xint
Name string
}

arr := []Point{
Point{1, "One"},
Point{3, "Three"},
Point{2, "Two"},
Point{4, "Four"},
}

log.Println("Before Sorting: ", arr)
sort.Slice(arr, func(i, j int) bool {
return arr[i].X < arr[i].X
})
log.Println("After Sorting: ", arr)

I wanted to see the slice of Point objects to be sorted after I called the 
sort function, but the slice remains unchanged. 

The play url is: 
https://play.golang.org/p/9KHfyL0xzVP

Any help on how I can get arr sorted in the above code ?

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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Golang HTTP POST handling

2018-02-20 Thread Sankar P
Thanks. Will do.

2018-02-21 4:31 GMT+05:30 Andrew Watson <andrewmoorewat...@gmail.com>:

> You should, of course, consider adding some rigor such as CSRF protection
> to that form! I'd suggest something like http://www.
> gorillatoolkit.org/pkg/csrf for that!
>
>
> On Tuesday, February 20, 2018 at 11:16:57 AM UTC-5, Sankar wrote:
>>
>> Hi,
>>
>> I have a Golang HTTP server which is consumed by mobile Apps via HTTP.
>>
>> For one workflow (reset-password) alone, I needed a web interface. So
>> instead of creating a new different webapp, I decided to make an endpoint
>> emit text/html instead of JSON and then serve a static HTML page, which
>> will then do a POST request.
>>
>> The same endpoint will serve HTML on HTTP GET and will process the values
>> in HTTP POST.
>>
>> However, I am not able to get the POST parameters in my HTTP request.
>> Even after a succesful req.ParseForm, my req.Form returns nil.
>>
>> I have attached the complete example.go file in the file, which you can
>> run offline. The relevant code section is:
>>
>> func alterPasswordHandler(res http.ResponseWriter, req *http.Request) {
>> if req.Method == http.MethodGet {
>> body := `
>> 
>> 
>> 
>> Password
>> 
>> Repeat Password
>> > required>
>> Change Password
>> 
>> 
>> 
>> `
>> res.WriteHeader(http.StatusOK)
>> res.Header().Set("Content-Type", "text/html")
>> res.Write([]byte(body))
>> } else if req.Method == http.MethodPost {
>> err := req.ParseForm()
>> log.Println(err, req.Form)  // <<<<<<<<<<< req.Form is nil
>> }
>> }
>>
>> What am I doing wrong ? I do get the POST request but without the
>> password fields as part of the POST body. Any help ?
>>
>> Thanks.
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/HxLT6NlzKlY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Golang HTTP POST handling

2018-02-20 Thread Sankar P
Perfect. Thanks. This is what I wanted. I just replaced id with name and it
started working.

2018-02-20 21:59 GMT+05:30 <matthewju...@gmail.com>:

> This worked for me in a project. My form is 
> and the input is . On the server I
> use r.ParseForm then r.FormValue("password").
>
> Matt
>
> On Tuesday, February 20, 2018 at 10:16:57 AM UTC-6, Sankar wrote:
>
>> Hi,
>>
>> I have a Golang HTTP server which is consumed by mobile Apps via HTTP.
>>
>> For one workflow (reset-password) alone, I needed a web interface. So
>> instead of creating a new different webapp, I decided to make an endpoint
>> emit text/html instead of JSON and then serve a static HTML page, which
>> will then do a POST request.
>>
>> The same endpoint will serve HTML on HTTP GET and will process the values
>> in HTTP POST.
>>
>> However, I am not able to get the POST parameters in my HTTP request.
>> Even after a succesful req.ParseForm, my req.Form returns nil.
>>
>> I have attached the complete example.go file in the file, which you can
>> run offline. The relevant code section is:
>>
>> func alterPasswordHandler(res http.ResponseWriter, req *http.Request) {
>> if req.Method == http.MethodGet {
>> body := `
>> 
>> 
>> 
>> Password
>> 
>> Repeat Password
>> > required>
>> Change Password
>> 
>> 
>> 
>> `
>> res.WriteHeader(http.StatusOK)
>> res.Header().Set("Content-Type", "text/html")
>> res.Write([]byte(body))
>> } else if req.Method == http.MethodPost {
>> err := req.ParseForm()
>> log.Println(err, req.Form)  // <<<<<<<<<<< req.Form is nil
>> }
>> }
>>
>> What am I doing wrong ? I do get the POST request but without the
>> password fields as part of the POST body. Any help ?
>>
>> Thanks.
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/HxLT6NlzKlY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Golang HTTP POST handling

2018-02-20 Thread Sankar
Hi,

I have a Golang HTTP server which is consumed by mobile Apps via HTTP. 

For one workflow (reset-password) alone, I needed a web interface. So 
instead of creating a new different webapp, I decided to make an endpoint 
emit text/html instead of JSON and then serve a static HTML page, which 
will then do a POST request. 

The same endpoint will serve HTML on HTTP GET and will process the values 
in HTTP POST.

However, I am not able to get the POST parameters in my HTTP request. Even 
after a succesful req.ParseForm, my req.Form returns nil.

I have attached the complete example.go file in the file, which you can run 
offline. The relevant code section is:

func alterPasswordHandler(res http.ResponseWriter, req *http.Request) {
if req.Method == http.MethodGet {
body := `



Password

Repeat Password

Change Password



`
res.WriteHeader(http.StatusOK)
res.Header().Set("Content-Type", "text/html")
res.Write([]byte(body))
} else if req.Method == http.MethodPost {
err := req.ParseForm()
log.Println(err, req.Form)  // <<< req.Form is nil
}
}

What am I doing wrong ? I do get the POST request but without the password 
fields as part of the POST body. Any help ?

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.
For more options, visit https://groups.google.com/d/optout.


example.go
Description: Binary data


Re: [go-nuts] Cloud Functions Golang Support

2018-02-07 Thread Sankar P
Hey Googlers,

Any help on this ? I would love to choose GCE, but will have to go with AWS
if there are no updates here. Thanks.

31 ஜன., 2018 முற்பகல் 12:08 அன்று, "Sankar" <sankar.curios...@gmail.com>
எழுதியது:

> Hi
>
> When is Golang support for Cloud functions in GCP expected ? I am starting
> off a new project and would love to use GCP over AWS, but lambda already
> supports Golang. Is there an approximate ETA for Golang in Google Cloud
> functions ?
>
> Thanks.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/62ec2LsSXtQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.


[go-nuts] Cloud Functions Golang Support

2018-01-30 Thread Sankar
Hi

When is Golang support for Cloud functions in GCP expected ? I am starting 
off a new project and would love to use GCP over AWS, but lambda already 
supports Golang. Is there an approximate ETA for Golang in Google Cloud 
functions ?

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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] acme, letsencrypt and different HTTPS ports

2017-11-16 Thread Sankar
Hi

I have an EC2 vm where I want to run two go https servers on different 
ports.

I am using letsencrypt for the certificates and the code is like:

server1.go: log.Fatal(http.Serve(autocert.NewListener("api1.example.com"), 
http.DefaultServeMux))
server2.go: log.Fatal(http.Serve(autocert.NewListener("api2.example.com"), 
http.DefaultServeMux))

I want api1 to listen on port 443 and want api2 to listed on port 8080. Is 
it possible to achieve this via autocert at all ? If not, are there any 
other hacks to get multiple ports exposed from the same machine using 
letsencrypt ? I am deploying server1.go manually (via a systemd script) and 
server2 via a docker container, if it matters.

Any help ?

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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: appengine golang logs

2017-11-04 Thread Sankar P
Thanks. I did not know this. I assumed that the only difference between
flexible and standard was the pricing, I was wrong. Thanks for the link.

2017-11-04 13:06 GMT+05:30 David Arroyo <dr...@aqwari.net>:

> Sankar,
>
> Have you tried using the Flexible environment? Flex provides a more
> "conventional" environment for your programs. There are some tradeoffs
> compared with App Engine Standard, but it should be easier to stay portable.
>
> David
>
> [1]: https://cloud.google.com/appengine/docs/flexible/go/
> writing-application-logs
>
>
> On Sat, Nov 4, 2017, at 03:26 AM, Sankar P wrote:
>
> Tried something similar already.
>
> context.Background() does not work with the appengine log package and
> panics at runtime. Passing nil also did not work.
>
> Probably initialising the AELogAdapter with a ctx from appengine request,
> in the _ah start handler is the only way. Thanks for the idea.
>
> I, for one, though wish that there was a simpler way.
>
> 2017-11-04 12:47 GMT+05:30 Gulácsi Tamás <tgulacs...@gmail.com>:
>
> Sth. along https://play.golang.org/p/BwlbkxMLdw ?
>
> Sankar P <sankar.curios...@gmail.com> ezt írta (időpont: 2017. nov. 4.,
> Szo, 8:10):
>
> There is no log.SetWriter in either the builtin log package or the
> appengine log package. There is a log.SetOutput which I mentioned in my
> original mail, but I am not able to understand how to connect it to the
> appengine logs.
>
> 2017-11-04 11:44 GMT+05:30 Tamás Gulácsi <tgulacs...@gmail.com>:
>
> Use log.SetWriter to divert log calls to appenginelog, if deployed there.
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/to
> pic/golang-nuts/XbhcR5eFdno/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
> --
> Sankar P
> http://psankar.blogspot.com
>
>
>
>
> --
> Sankar P
> http://psankar.blogspot.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.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/XbhcR5eFdno/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: appengine golang logs

2017-11-04 Thread Sankar P
Tried something similar already.

context.Background() does not work with the appengine log package and
panics at runtime. Passing nil also did not work.

Probably initialising the AELogAdapter with a ctx from appengine request,
in the _ah start handler is the only way. Thanks for the idea.

I, for one, though wish that there was a simpler way.

2017-11-04 12:47 GMT+05:30 Gulácsi Tamás <tgulacs...@gmail.com>:

> Sth. along https://play.golang.org/p/BwlbkxMLdw ?
>
> Sankar P <sankar.curios...@gmail.com> ezt írta (időpont: 2017. nov. 4.,
> Szo, 8:10):
>
>> There is no log.SetWriter in either the builtin log package or the
>> appengine log package. There is a log.SetOutput which I mentioned in my
>> original mail, but I am not able to understand how to connect it to the
>> appengine logs.
>>
>> 2017-11-04 11:44 GMT+05:30 Tamás Gulácsi <tgulacs...@gmail.com>:
>>
>>> Use log.SetWriter to divert log calls to appenginelog, if deployed there.
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "golang-nuts" group.
>>> To unsubscribe from this topic, visit https://groups.google.com/d/
>>> topic/golang-nuts/XbhcR5eFdno/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> golang-nuts+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Sankar P
>> http://psankar.blogspot.com
>>
>


-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: appengine golang logs

2017-11-04 Thread Sankar P
There is no log.SetWriter in either the builtin log package or the
appengine log package. There is a log.SetOutput which I mentioned in my
original mail, but I am not able to understand how to connect it to the
appengine logs.

2017-11-04 11:44 GMT+05:30 Tamás Gulácsi <tgulacs...@gmail.com>:

> Use log.SetWriter to divert log calls to appenginelog, if deployed there.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/XbhcR5eFdno/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: appengine golang logs

2017-11-03 Thread Sankar P
I knew about this package. I mentioned about this in my mail itself :-)

I wanted a different way as it is not always possible to replace "log"
calls in all the existing code. Some libraries need to be used in binaries
which will be deployed outside appengine. They should not have a dependency
on appengine libraries ideally.


2017-11-03 23:01 GMT+05:30 Jim Cote <jc...@libertyfund.org>:

> In appengine you have to use google.golang.org/appengine/log package.
> The log calls must have a context passed to it.
>
> See https://cloud.google.com/appengine/docs/standard/go/logs/reference.
>
>
> On Friday, November 3, 2017 at 3:58:34 AM UTC-4, Sankar wrote:
>>
>> Hi
>>
>>
>> I have a golang file where I have code like:
>>
>>
>> log.Fatal("My error message: ", err)
>>
>>
>> When the above statement is executed, In the appengine logviewer, I get
>> something like:
>>
>> panic: os.Exit called goroutine 1 [running]:
>> os.Exit(0x1)
>> go/src/os/proc.go:58
>> <https://console.cloud.google.com/debug/fromlog?appModule=default=20171103t130151=go%2Fsrc%2Fos%2Fproc.go=58=59fc1ca5000391bb3a15d19c=1509694618092435000=0=celtic-facility-184703>
>> +0x7c log.Fatal(0xc008549f60, 0x2, 0x2)
>> go/src/log/log.go:303
>> <https://console.cloud.google.com/debug/fromlog?appModule=default=20171103t130151=go%2Fsrc%2Flog%2Flog.go=303=59fc1ca5000391bb3a15d19c=1509694618092435000=0=celtic-facility-184703>
>> +0x79 main.main()
>> main.go:42
>> <https://console.cloud.google.com/debug/fromlog?appModule=default=20171103t130151=main.go=42=59fc1ca5000391bb3a15d19c=1509694618092435000=0=celtic-facility-184703>
>> +0x201
>>
>> But I dont get any error message. The main.go:42 corresponds to the
>> log.Fatal line in my code but I do not get to see the error message that is
>> printed as part of the log statement.
>>
>> I see that appengine package has a "Log" function which may print the
>> AppLogs such that they can be viewed from the Google Appengine log console
>> itself.
>>
>> My question is, can the golang default log package be somehow instructed
>> to redirect to appengine ? Something like:
>>
>> if env == "AppEngine" {
>>   log.SetOutput(appengine.DefaultLogger)
>> }
>>
>> in my main file ? This way, I get to make my code not locked to google
>> cloud and also can deploy existing code which uses log already.
>>
>> Any pointers ?
>>
>> Thanks.
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/XbhcR5eFdno/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] appengine golang logs

2017-11-03 Thread Sankar
Hi


I have a golang file where I have code like:


log.Fatal("My error message: ", err)


When the above statement is executed, In the appengine logviewer, I get 
something like:

panic: os.Exit called goroutine 1 [running]: 
os.Exit(0x1)
go/src/os/proc.go:58 

 
+0x7c log.Fatal(0xc008549f60, 0x2, 0x2) 
go/src/log/log.go:303 

 
+0x79 main.main()
main.go:42 

 
+0x201

But I dont get any error message. The main.go:42 corresponds to the 
log.Fatal line in my code but I do not get to see the error message that is 
printed as part of the log statement.

I see that appengine package has a "Log" function which may print the 
AppLogs such that they can be viewed from the Google Appengine log console 
itself.

My question is, can the golang default log package be somehow instructed to 
redirect to appengine ? Something like:

if env == "AppEngine" {
  log.SetOutput(appengine.DefaultLogger) 
}

in my main file ? This way, I get to make my code not locked to google 
cloud and also can deploy existing code which uses log already.

Any pointers ?

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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Appengine and main package

2017-11-02 Thread Sankar P
Thanks.

2017-11-02 10:06 GMT+05:30 Chris Broadfoot <ch...@chrisbroadfoot.id.au>:

> You can use a main package.
>
> package main
>
> import (
>"net/http"
>"google.golang.org/appengine"
> )
>
> func main() {
>http.HandleFunc(...)
>appengine.Main()
> }
>
>
> On Wednesday, November 1, 2017 at 12:04:14 AM UTC-7, Tamás Gulácsi wrote:
>>
>> Just move your main to a realmain pkg, and have a shim that just calls it.
>> I used to create a "func Main() error" and a main which calls this, and
>> log,Fatal on error.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/Vce6234vk8E/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Appengine and main package

2017-10-31 Thread Sankar
Hi

I am evaluating appengine for a golang project. It is a simple REST server 
with a bunch of endpoints. I am currently deploying it in AWS, in an EC2 
instance. I have written a systemd script file which will take care of 
launching the webserver as a systemd service (so that it is always up etc.).

I am evaluating appengine and I see that we need to change the package main 
to something else, as appengine needs to have its own main package. This is 
kind of annoying as now I cannot easily test in my dev laptop or have the 
same code across my EC2 instance and appengine. So, are there any tricks to 
switch the main package automatically when I am deploying to appengine ? 
(Some kind of pre-push patch or something ?)

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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Tools for 80 column split for golang

2017-09-07 Thread Sankar P
Even with most modern laptops, I found having 80 column limit is very
useful, when we split panes and read code. May be it is just my personal
preference :)

2017-09-07 12:05 GMT+05:30 Jakob Borg <ja...@kastelo.net>:

> On 7 Sep 2017, at 06:10, Sankar <sankar.curios...@gmail.com> wrote:
> >
> > Are there any tools available for golang to split long functions so that
> they can fit in 80 columns (as long as possible) ?
>
> Don't fear longer lines, most of us are not on text mode terminals any
> more. :)
>
> When it becomes *too* long it's probably hard to read due to being a too
> large or too complex expression, not the line length per se. My preferred
> solution would be to split it up with a variable or two. I don't think
> there is a tool for that, it requires human consideration.
>
> //jb
>
>


-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Tools for 80 column split for golang

2017-09-06 Thread Sankar
Hi

Are there any tools available for golang to split long functions so that 
they can fit in 80 columns (as long as possible) ? 

For example:

```
mux.Handle("/login", handlers.LoggingHandler(os.Stderr, 
http.HandlerFunc(lh.LoginHandler)))
mux.Handle("/add-referrer", handlers.LoggingHandler(os.Stderr, 
auth.Trace(auth.IsAuthenticated(auth.IsReferrer(http.HandlerFunc(lh.AddReferrerHandler))
```

could become:

```
mux.Handle(
"/login",
handlers.LoggingHandler(os.Stderr, http.HandlerFunc(lh.LoginHandler)))
mux.Handle(
"/add-referrer",
handlers.LoggingHandler(
os.Stderr,
auth.Trace(
auth.IsAuthenticated(
auth.IsReferrer(http.HandlerFunc(lh.AddReferrerHandler)),
),
),
),
)
```
Google groups will make the indents in the above snippet display wrong, but 
you get the idea.

Are there any tools (Similar to prettier for javascript) or techniques for 
getting this ?

Thanks.

Sankar

-- 
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.


Re: [go-nuts] Re: golang continuous deployment & gitlab

2017-08-20 Thread Sankar P
Thanks a lot. This is good :)

2017-08-20 14:09 GMT+05:30 Diego Medina <fmpwiz...@gmail.com>:

> Hi,
>
> At work we have all of our deployment logic written in ansible and simply
> call an ansible playbook from jenkins (gitlab-ci in your case)
>
> Here is a sample project using ansible
>
> https://github.com/fmpwizard/mrwilson/tree/master/ansible
>
> it has all the roles, code, etc needed to start with a fresh fedora server
> provided by digital ocean (so bare that it starts by installing python
> using the raw command and then continues to use regular ansible code)
>
> This file:
>
> https://github.com/fmpwizard/mrwilson/blob/master/ansible/all_roles.sh
>
> shows you the commands your ci would run, depending on what you need.
>
> this deploys the binary:
> ansible-playbook -i hosts/production playbooks/deploy.yml --ask-vault-pass
> -u root
>
> and after it is deployed,
>
> ansible-playbook -i hosts/production playbooks/site-state.yml
> --ask-vault-pass --extra-vars "app_state=restart" -u root
>
> restarts systemd
>
> No docker in this setup,
>
> Hope it helps.
>
> Diego
>
>
>
>
> On Saturday, August 19, 2017 at 3:03:07 PM UTC-4, Sankar wrote:
>>
>> Hi
>>
>> I have a golang HTTP server that I am deploying on an AWS EC2 VM, as a
>> systemd service.
>>
>> Right now, I am manually deploying the service as follows:
>>
>> 1) vm$  sudo systemctl stop 
>> 2) dev$ scp  
>> 3)psql$ Apply migrations manually
>> 4) vm$  sudo stystemctl start 
>> 4) vm$  sudo stystemctl status  ;# Just to check
>>
>>
>> I maintain my sources in gitlab and my database is postgres.
>>
>> I am planning to use gitlab-ci for preparing cross-compiled systemd
>> binaries and also sqitch for postgres migrations.
>>
>> I wanted to ask if there are any advises (or links to
>> tools/blogposts/scripts) from existing gitlab (or even github+ci) + golang
>> users, who do continuous deployments already. I can have some downtime and
>> 100% uptime is not important for me. Also, one instance of my server is
>> enough and there is no need for HA, load-balancing, etc. as of now, as it
>> is just an internal low-traffic service.
>>
>> I also thought of preparing an ubuntu ppa repository internally, on the
>> lines of https://about.gitlab.com/2016/10/12/automated-debian-pack
>> age-build-with-gitlab-ci/
>>
>> I am not using Docker (containers) because I do not want another layer
>> which may cause some unknown problems (performance, networking, etc.) which
>> I do not want to end up debugging.
>>
>> Any advises or suggestions or links that would help me ? Thanks.
>>
>> Sankar
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/1jcdyycttd0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] golang continuous deployment & gitlab

2017-08-19 Thread Sankar
Hi

I have a golang HTTP server that I am deploying on an AWS EC2 VM, as a 
systemd service.

Right now, I am manually deploying the service as follows:

1) vm$  sudo systemctl stop 
2) dev$ scp  
3)psql$ Apply migrations manually
4) vm$  sudo stystemctl start 
4) vm$  sudo stystemctl status  ;# Just to check


I maintain my sources in gitlab and my database is postgres.

I am planning to use gitlab-ci for preparing cross-compiled systemd 
binaries and also sqitch for postgres migrations.

I wanted to ask if there are any advises (or links to 
tools/blogposts/scripts) from existing gitlab (or even github+ci) + golang 
users, who do continuous deployments already. I can have some downtime and 
100% uptime is not important for me. Also, one instance of my server is 
enough and there is no need for HA, load-balancing, etc. as of now, as it 
is just an internal low-traffic service.

I also thought of preparing an ubuntu ppa repository internally, on the 
lines 
of 
https://about.gitlab.com/2016/10/12/automated-debian-package-build-with-gitlab-ci/

I am not using Docker (containers) because I do not want another layer 
which may cause some unknown problems (performance, networking, etc.) which 
I do not want to end up debugging.

Any advises or suggestions or links that would help me ? Thanks.

Sankar

-- 
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.


Re: [go-nuts] Arrays, structs and marshalJSON

2017-08-09 Thread Sankar P
aah. Damn it :-) Thanks a lot. I am hitting myself for missing this.

2017-08-09 16:40 GMT+05:30 Jakob Borg <ja...@kastelo.net>:

> On 9 Aug 2017, at 12:26, Sankar <sankar.curios...@gmail.com> wrote:
> >
> > Now for the same, Item object, the json.Marshal function returns two
> different strings for the `Item` object.
> >
> > If you run the playground url, you will find that:
> >
> > {"Items":[{"SD":"2009-11-10T23:00"}]}
> > {"Item":{"SD":"2009-11-10T23:00:00Z"}}
> >
> > are two different outputs (notice the "seconds" and the "Z" in the
> second line). I expected both the lines to print the same output for "SD"
> as the same object is re-used for them both.
> >
> > Now, should I define MarshalJson and UnmarshalJSON function for the
> []Item too (after making it a custom struct) ?
> >
> > Or is this a bug, or do I misunderstand anything ?
>
> The issue is that you have defined MarshalJSON as a method with a pointer
> receiver, while the JSON marshaller will access it through an interface
> value that is not addressable. Instead, declare the MarshalJSON method with
> a value receiver:
>
> func (ct CustomTime) MarshalJSON() ([]byte, error) { ... }
>
> //jb
>
>


-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Arrays, structs and marshalJSON

2017-08-09 Thread Sankar
Hi,

There is a difference in the way MarshalJSON of a struct is called when an 
instance of a struct is either part of an array or embedded directly inside 
another object. I am not sure if it is a bug or if it is the intended 
behavior. 

Please see the Go source available at: https://play.golang.org/p/NpWj4VAjrz

I have a custom struct `CustomTime` which has a MarshalJSON and an 
UnmarshalJSON function.

Now I have a struct `Item`, which has an instance of the above `CustomTime` 
struct.

There are two other structs, ItemsArray and ItemsMember where Item is part 
of an array or a direct member.

type ItemsArray struct {
Items []Item
}

type ItemsMember struct {
Item Item
}

Now for the same, Item object, the json.Marshal function returns two 
different strings for the `Item` object.

If you run the playground url, you will find that:

{"Items":[{"SD":"2009-11-10T23:00"}]} 

{"Item":{"SD":"2009-11-10T23:00:00Z"}}


are two different outputs (notice the "seconds" and the "Z" in the second 
line). I expected both the lines to print the same output for "SD" as the 
same object is re-used for them both.

Now, should I define MarshalJson and UnmarshalJSON function for the []Item 
too (after making it a custom struct) ?

Or is this a bug, or do I misunderstand anything ?

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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] golang on ec2; terraform, salt, etc.

2017-07-25 Thread Sankar
Hi

I have a golang REST api server. I cross-compile the monolithic golang 
binary with GOOS=linux GOARCH=amd64 from my macbook (developer machine) and 
then scp the binary to a ec2 vm. I have written a systemd service file to 
manually bring down the service before the scp and bring up after the scp.

I use RDS for database and run any migrations that are needed, after the 
scp and before the service restart.

Now I have reached a stage where I want the deployments to be continuous 
and preferably from my CI system.  I have already written a Dockerfile 
which is used in the CI system for testing. I do not want to use kubernetes 
or anything complex at the moment because I am going to have only one 
instance of my monolithic binary and also a free tier vm is sufficient for 
my current needs.

I am looking for tools / processes / best practices that people are 
following to automate deploy of golang binaries on EC2. I prefer to use a 
cloud-vendor-neutral-tool (such as terraform or saltstack) instead of 
cloudformation. Can you share your golang production deploy experience ?

Thanks a lot.


-- 
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.


Re: [go-nuts] letsencrypt, localhost and autocert

2017-06-09 Thread Sankar P
Thank you so much Axel Wagner. I was able to get everything working, once I
added the A record. Everything worked so magically together correctly :)

2017-06-07 23:33 GMT+05:30 Axel Wagner <axel.wagner...@googlemail.com>:

> On Wed, Jun 7, 2017 at 7:22 PM, Sankar P <sankar.curios...@gmail.com>
> wrote:
>
>>
>> 2017-06-06 22:52 GMT+05:30 Axel Wagner <axel.wagner...@googlemail.com>:
>>
>>> tl;dr: You need a) a publicly routed IP address (either IPv4 or IPv6 is
>>> fine), b) a publicly resolvable domain that points to that IP address and
>>> c) actually point your client (browser) to that domain.
>>
>>
>> a) I created an AWS VM with a public-ip address. I verified that the
>> machine is accesible by ssh-ing into it.
>> b) In my domain name provider (Gandi, if it matters), I added a
>> web-forwarding rule to forward all incoming requests to
>> http://api.mydomain.com to https://public-ip
>>
>
> This doesn't sound right. It seems that this would imply a) that your
> DNS-provider actually does HTTP proxying, which is definitely *not* what
> you want, you want to terminate the connection yourself and b) that your
> server still doesn't get an HTTP handshake for the Domain, as your client
> doesn't do the HTTP handshake with your server, but with the server of your
> DNS provider.
>
> You want to set up an A/ record for api.mydomain.com to point to your
> public IP.
>
> For testing, what Jim suggested below (entering the IP address into your
> host-file, or the local DNS cache of your router, for example) would also
> work. But you need to actually set up DNS to point to your server.
>
>
>> c) I ran a go server with that magical line: log.Fatal(http.Serve(aut
>> ocert.NewListener("mydomain.com <http://example.com/>"), handler))
>> in that public-ip
>>
>
> Note, that "api.mydomain.com" and "mydomain.com" are different domains.
> You need to list the same domains as arguments to NewListener as you are
> creating records for.
>
> If you want, feel free to send me your actual domain name off-list and I
> could verify, that you set it up correctly.
>
> BTW, note that none of these problems is specific to LetsEncrypt or the
> autocert package; you'd also need a correct DNS setup and everything if
> you'd use any other SSL certificate provider.
>
>
>>
>> Now if I try to access http://api.mydomain.com then I am not able to
>> reach this server, nor do I get any mail from letsencrypt about
>> certificates. What should I be doing extra ?
>>
>> Thank you everyone for the responses.
>>
>>
>> --
>> Sankar P
>> http://psankar.blogspot.com
>>
>
>


-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] letsencrypt, localhost and autocert

2017-06-07 Thread Sankar P
2017-06-06 22:52 GMT+05:30 Axel Wagner <axel.wagner...@googlemail.com>:

> tl;dr: You need a) a publicly routed IP address (either IPv4 or IPv6 is
> fine), b) a publicly resolvable domain that points to that IP address and
> c) actually point your client (browser) to that domain.


a) I created an AWS VM with a public-ip address. I verified that the
machine is accesible by ssh-ing into it.
b) In my domain name provider (Gandi, if it matters), I added a
web-forwarding rule to forward all incoming requests to
http://api.mydomain.com to https://public-ip
c) I ran a go server with that magical line: log.Fatal(http.Serve(autocert.
NewListener("mydomain.com <http://example.com/>"), handler))
in that public-ip

Now if I try to access http://api.mydomain.com then I am not able to reach
this server, nor do I get any mail from letsencrypt about certificates.
What should I be doing extra ?

Thank you everyone for the responses.


-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] letsencrypt, localhost and autocert

2017-06-06 Thread Sankar
Hi

I saw the tweet https://twitter.com/mholt6/status/848704744474292224 and 
decided to try out the code

log.Fatal(http.Serve(autocert.NewListener("mydomain.com 
"), handler)) 

but when I try to visit: https://localhost:443, I get an error on the 
server console as: server name component count invalid

Is there any detailed documentation on how to get letsencrypt working with 
golang ?

I am using go 1.8.3

Google gave me https://github.com/golang/go/issues/17053 , but I am not 
able to understand if the letsencrypt support is fully landed or not. Can 
anyone point me to docs and best practices for testing at localhost and 
deploying at production, with https and letsencrypt ? 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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] golang regex question

2017-06-02 Thread Sankar
I have a go string

dbConnStr1 := "user=someone password=something host=superduperhost 
sslmode=something"

the k=v pair in this string may be in any order, for example:

dbConnStr2 := "host=superduperhost user=someone password=something"


Notice the difference in the key order and also the missing "sslmode" key 
in the second instance.

Also, it is possible that instead of whitespace, the individual k,v pairs 
may be separated by newline too.

It is safe to assume that the values may not contain '=' as a content.

Given all these constraints:

Now I want to extract the unique keys and their corresponding values from 
the given string, using regexp. If it will help, I can give a list of all 
the possible keys that may come (username, password, host, sslmode), but I 
would ideally like a regex solution that works with any list of keys and 
values.

How to do this ? I understand that it may be possible with 
regexp.FindStringSubmatch but not able to wrap my head around writing the 
regexp.

P.s: I know that instead of using regexp, I can write strings.Split call 
and do it normally, but I want a regexp based solution.

Any help ?

Thanks.

PS: I have asked the same question in stackoverflow too and if you want to 
answer there, please 
see: 
https://stackoverflow.com/questions/44321199/golang-extract-unique-key-value-from-a-key-value-pair-string-using-regex

-- 
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.


[go-nuts] docker multi-stage builds and small binary sizes

2017-04-27 Thread Sankar
Anyone aware of links explaining if-we-can/how-to create lean containers 
for golang http servers by using the new multi-stage build options in 
Docker ? Similar to: https://codefresh.io/blog/node_docker_multistage/ 

That would be very handy than doing GOOS=linux builds and then copying the 
binary in to a docker SCRATCH/Alpine container.

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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Deploying go https servers

2017-03-10 Thread Sankar P
Just curios to know if I am going to use kubernetes for deployment, would
choosing Caddie make any difference (either good or bad) ? I will
investigate myself later, but wanted to know your opinion, incase you have
already done that. Thanks.

2017-03-10 20:46 GMT+05:30 Kevin Powick <kpow...@gmail.com>:

> I know you're just looking for a checklist, but we found it better to use
> Caddy (built in Go) as our web, and then have our Go API service proxied
> via that.  It's pretty awesome because it's so easy to use Caddy in that
> way.
>
> For example :
>
> http://mydomain/mypage will serve up your page, but you can tell Caddy to
> route requests for http://mydomain/api/dosomething to the port behind
> your firewall that your Go service is running on.
>
> Caddy also allows gives you http2 and automatic security via https
>
> https://caddyserver.com/
>
> For us, the big advantage is that we could focus on our Go API service
> being only that, and not a web page server as well.
>
> --
> Kevin Powick
>
>
> On Wednesday, 8 March 2017 14:02:50 UTC-5, Sankar wrote:
>>
>> Hi
>>
>> I have written a golang REST API server and a react webapp that talks to
>> this REST server. There is a mysql server that the golang server talks to.
>> There is an init script with a bunch of SQL statements to create a few
>> tables and indexes. Everything works fine in my local machine. I have
>> bought a domain name too. I have a VM on cloud with ssh access.
>>
>> I wanted to find out if there are any good blog posts or talks or
>> tutorials or "checklists" documenting the process to deploy such a golang
>> server + a web front end behind a domain name (example.com for the react
>> webapp and api.example.com for the golang) and both accessible only via
>> HTTPS, with the API Server probably behind a load balancer, and all
>> certificates being valid, etc.
>>
>> I understand that I can use kubernetes for such orchestration. But I
>> wanted to find out a deploy solution which could work reliably and easily
>> (without depending on too many third party projects) on AWS. GKE does not
>> exist in my region (India) and so cannot use Kube. Any pointers ?
>>
>> Thanks.
>>
>> Sankar
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/sTsDhJLKTqU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Deploying go https servers

2017-03-09 Thread Sankar P
Wow. This is a fantastic post. Thanks for sharing. I was expecting
something like this only.

2017-03-10 10:13 GMT+05:30 Dragos Harabor <dh...@harabor.com>:

> Does this help?
> https://blog.gopheracademy.com/advent-2016/exposing-go-on-the-internet/
>
> On Wednesday, March 8, 2017 at 7:49:37 PM UTC-8, Sankar wrote:
>>
>> I am looking more for a checklist of things to do, rather than a set of
>> tools.
>>
>> 2017-03-09 0:38 GMT+05:30 Shawn Milochik <shawn...@gmail.com>:
>>
>>> That sounds a good use-case for Ansible to me. It's pretty easy to use
>>> and get started.
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "golang-nuts" group.
>>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>>> pic/golang-nuts/sTsDhJLKTqU/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> golang-nuts...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Sankar P
>> http://psankar.blogspot.com
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/sTsDhJLKTqU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Deploying go https servers

2017-03-08 Thread Sankar P
I am looking more for a checklist of things to do, rather than a set of
tools.

2017-03-09 0:38 GMT+05:30 Shawn Milochik <shawn.m...@gmail.com>:

> That sounds a good use-case for Ansible to me. It's pretty easy to use and
> get started.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/sTsDhJLKTqU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Deploying go https servers

2017-03-08 Thread Sankar
Hi

I have written a golang REST API server and a react webapp that talks to 
this REST server. There is a mysql server that the golang server talks to. 
There is an init script with a bunch of SQL statements to create a few 
tables and indexes. Everything works fine in my local machine. I have 
bought a domain name too. I have a VM on cloud with ssh access. 

I wanted to find out if there are any good blog posts or talks or tutorials 
or "checklists" documenting the process to deploy such a golang server + a 
web front end behind a domain name (example.com for the react webapp and 
api.example.com for the golang) and both accessible only via HTTPS, with 
the API Server probably behind a load balancer, and all certificates being 
valid, etc.

I understand that I can use kubernetes for such orchestration. But I wanted 
to find out a deploy solution which could work reliably and easily (without 
depending on too many third party projects) on AWS. GKE does not exist in 
my region (India) and so cannot use Kube. Any pointers ?

Thanks.

Sankar

-- 
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.


[go-nuts] Minimizing golang docker images

2017-02-24 Thread Sankar
Hi

I have a bunch of services (all sources in a single git project) which I 
want to dockerize and deploy in kubernetes (and run CI too preferably via 
minikube).

I have seen that it is possible to generate small docker images for golang 
HTTP servers by building them separately outside the Dockerfile that will 
be used for deployment, such 
as: 
http://samuraiprogrammer.net/blog/way-to-reduce-docker-image-size-with-tarball/

But the above approach of two Dockerfiles for each service, makes it very 
difficult to manage the sources. I wanted to know if there are any 
hacks/best-practices for reducing the docker image sizes for golang 
microservices but without creating two Dockerfiles for each service. Any 
help ?

Thanks.

Sankar

-- 
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.


Re: [go-nuts] Re: gRPC golang server and client testing

2016-12-12 Thread Sankar P
I did not find any :(

2016-12-12 1:28 GMT+05:30 <p.kart...@yonego.nl>:

> Would be interested to learn of if you found a good solution.
>
>
> On Saturday, April 23, 2016 at 9:31:19 PM UTC+2, Sankar wrote:
>>
>> Hi
>>
>> I have a .proto file which I ran with protoc to generate the _pb.go file.
>> I then wrote a server and a client program that uses the above _pb.go
>> program. Now what is the best way to unit test the server and client pieces
>> ? (complete with mocking, benchmarks for both client and server; end-to-end
>> testing, etc.)
>>
>> IOW, I am trying to find out the test programs for
>> https://github.com/grpc/grpc-go/blob/master/examples/hel
>> loworld/greeter_server/main.go and https://github.com/grpc/gr
>> pc-go/blob/master/examples/helloworld/greeter_client/main.go
>>
>> Thanks.
>>
>> Sankar
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/LuNb71evp84/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] protobuf go and pointers

2016-08-03 Thread Sankar P
Thanks for the explanation. It does look much better in proto3. I will
see if it will be possible to switch to proto3.

2016-08-03 21:37 GMT+05:30 Ian Lance Taylor <i...@golang.org>:
> On Wed, Aug 3, 2016 at 8:58 AM, Sankar <sankar.curios...@gmail.com> wrote:
>>
>> I have a .proto2 file, like:
>>
>> message s {
>> optional double a = 1;
>> }
>>
>> When I run protoc and generate the .pb.go file, it contains code like:
>>
>> type S struct {
>> A*float64 `protobuf:"fixed64,1,opt,name=a"
>> json:"a,omitempty"`
>> XXX_unrecognized []byte   `json:"-"`
>> }
>>
>> Why is the A field here a pointer instead of a normal float64 ?
>
> Because proto2 records not only the value of each field, but also
> whether the field is present or not.  Using a pointer is how the Go
> implementations indicates whether the field is present.
>
> This is better in proto3.  If you can switch to proto3, do so.
>
> Ian



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] protobuf go and pointers

2016-08-03 Thread Sankar
Hi

I have a .proto2 file, like:

message s {
optional double a = 1;
}

When I run protoc and generate the .pb.go file, it contains code like:

type S struct {
A*float64 `protobuf:"fixed64,1,opt,name=a" 
json:"a,omitempty"`
XXX_unrecognized []byte   `json:"-"`
}

Why is the A field here a pointer instead of a normal float64 ? Is there 
any way to get it a float64 ?

I ask this because, the code becomes too verbose. If it was just a float, I 
would have written code like:

var s pb.S
s.A, err = strconv.ParseFloat(strings.Replace(lines[0], ",", "", -1), 64)

whereas now I am forced to write:

f, err = strpconv.ParseFloat(strings.Replace(lines[0], ",", "", -1), 64)
if err != nil {
}
s.A = protobuf.Float64(f)


This is one extra line everywhere s.A is used. Also, in case of float64 it 
may be just one line. But if I have other structs as member elements in my 
structs, this code becomes even more complicated. Is there any way to 
generate code such that actual struct instances and datatype instances will 
be used instead of pointers ?

Thanks.

Sankar



-- 
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.


Re: [go-nuts] Extracting table data out of PDFs

2016-07-11 Thread Sankar P
2016-07-11 15:34 GMT+05:30 Sankar P <sankar.curios...@gmail.com>:
>> I don't know if it does what you want, but have you looked at
>> https://godoc.org/rsc.io/pdf ?
>
> It seems to be unmaintained. I tried loading a complex PDF with plenty
> of tables and it hung infinitely on Content() call in the first page.
> I lost interest after that. Thanks.

Comment by Russ Cox on
https://github.com/rsc/pdf/issues/3#issuecomment-168734094 made me
consider it unmaintained. Forgot to paste the link in the previous
mail. Sorry.


-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Extracting table data out of PDFs

2016-07-11 Thread Sankar P
> I don't know if it does what you want, but have you looked at
> https://godoc.org/rsc.io/pdf ?

It seems to be unmaintained. I tried loading a complex PDF with plenty
of tables and it hung infinitely on Content() call in the first page.
I lost interest after that. Thanks.


-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Extracting table data out of PDFs

2016-06-30 Thread Sankar P
Yes, I did come across your service when I was searching. I have some
PII information and so did not try the service. Having an on-premise
solution is encouraging. I will play with it. Thanks.

2016-06-30 14:35 GMT+05:30 Peter Waller <pe...@pdftables.com>:
> Hi Sankar,
>
> It may not be exactly what you're looking for but I can't resist the
> opportunity to plug our product! PDFTables.com has a remote API, you can see
> an example of how to use it here:
>
> https://github.com/pdftables/api/blob/master/go/cmd/pdftables-api/main.go
>
> You can get an API key and find out more from here:
>
> https://pdftables.com/api
>
> I created the repository in response to your request but we have been using
> this code internally for a long time now without issue, and the site has
> been alive and stable since 2014.
>
> We also offer the software as an on-premises appliance which you access
> using the same API.
>
> Feel free to reach out to he...@pdftables.com or me if you have any further
> questions.
>
> Regards,
>
> - Peter
>
>
> On 30 June 2016 at 09:35, Sankar <sankar.curios...@gmail.com> wrote:
>>
>> Hi
>>
>> Are there any stable/production-quality golang libraries that people are
>> aware of which could read and extract tabular data out of PDF documents ?
>>
>> Thanks
>>
>> Sankar
>>
>> --
>> 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.
>
>



-- 
Sankar P
http://psankar.blogspot.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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Extracting table data out of PDFs

2016-06-30 Thread Sankar
Hi

Are there any stable/production-quality golang libraries that people are 
aware of which could read and extract tabular data out of PDF documents ?

Thanks

Sankar

-- 
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.


[go-nuts] generating interfaces from proto3 (grpc)

2016-06-18 Thread Sankar
Hi

I've a proto3 file:

==
message Any {
}

message InsertParams {
Any Record = 1;
}

service myService {
rpc Insert (InsertParams) returns (InsertResponse);
 }


where I have an "Insert" API which expects a InsertParams struct as the 
parameter. However, the InsertParams struct has a Record field, that is 
needed to work across any datatype (a byte array, struct, string, int, 
etc.).

So, I created an Any type of message in the proto file. However, the 
generated _pb.go file is making the "Any" as a struct instead of an 
interface.

Is there any way to define a proto grpc API which will work across a 
generic type of parameter ?

Thanks.

Sankar

-- 
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.