[go-nuts] Help understanding slices, variable arguments, and passing slices to functions

2023-09-25 Thread Andrew Pillar
I have some code whereby I am iterating over some data, putting that
data into a buffer slice defined outside the loop, then passing the
contents of that buffer slice to a function which returns a struct
containing that data. See the playground link as a stripped down
demonstration of what I'm actually doing:
https://go.dev/play/p/66Ynp7W2TQ8

With the above example, the code outputs,

[1 2 3]
[1 2 3]

instead of what I would expect, which would be,

[0 1 2]
[1 2 3]

I have two fixes for this. The first would be to move the buf slice
inside the most outer loop so that a new buffer slice is created on
each iteration. The other is to allocate a new tmp slice within the
MakeValues function and to copy the contents of a to that tmp slice and
use that in the Args struct parameter.

My initial understanding of slices in Go, is that they are passed by
value to functions, so a copy of the slice's contents should be given
to the MakeValues function in this case, yet the observed behaviour
indicates that this is not the case?

As stated, I have a solution to my issue, I would just like to better
understand the semantics of slices and how they are passed to
functions. And what the best approach to take for my situation would
be, whereby I am using a temporary buffer slice that is cleared after
each iteration for storing data to then pass somewhere else.

- Andrew

-- 
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/ede82dfcca6e43062309440727800e15533d0c8f.camel%40andrewpillar.com.


[go-nuts] req an HTTP scripting language

2022-06-14 Thread Andrew Pillar
Hi all,

req is an HTTP scripting language that I've been working on. The
intention behind it is to provide a high-level language for quickly
scraping data off of web APIs or web pages. Just recently, v1.1.0 has
been released which adds support for working with cookies.

Feel free to check it out if weird scripting languages are your thing.

GitHub: https://github.com/andrewpillar/req
Initial blog post:
https://andrewpillar.com/programming/2022/02/26/req-an-http-scripting-language/

-- 
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/de215af833a37cb7f7ca1ba724d9260d3d93ce70.camel%40andrewpillar.com.


Re: [go-nuts] Structured configuration in Go

2022-04-10 Thread Andrew Pillar
> I think there are two big advantages to making your application
> consume either plain JSON or YAML configs:
> 1. Everyone is familiar with them
> 2. You can use a more advanced tool like cue or jsonnet to generate
> them

I can see why people would prefer JSON, and I think it's fine for
storing configuration that is edited by the program itself. I don't
think JSON is a very good interface for humans however as it can be
surprisingly verbose at times.

-- 
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/e1935a71820ec9b821054590910ecd0ef438fe2e.camel%40andrewpillar.com.


Re: [go-nuts] Structured configuration in Go

2022-04-09 Thread Andrew Pillar
> Out of interest, have you come across CUE?

> 
I have heard of it, but not explored it in depth. At a glance it seems
too heavyweight for what I wanted.

-- 
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/74afd692895542714a70d3cf884b1db1ea8fc2a9.camel%40andrewpillar.com.


[go-nuts] Structured configuration in Go

2022-04-09 Thread Andrew Pillar
An article I wrote about a new configuration library I developed in Go
for working with structured configuration.

Article:
https://andrewpillar.com/programming/2022/04/09/structured-configuration-in-go/
Repo: https://github.com/andrewpillar/config

-- 
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/cce0eeb5a085f6c7539774790d813cef254a4a0b.camel%40andrewpillar.com.


Re: [go-nuts] Golang library for - ORM & Schema Migration

2019-10-01 Thread Andrew Pillar
I created a simple migration tool called mgrt [1], which operates on pure SQL
scripts that are defined by the user. It has support for MySQL, SQLite and
PostgreSQL. Give it a try if you're looking for a simple migration tool that
just uses plain SQL under the hood. It's written in Go, so building it won't be
too hard.

[1] - https://github.com/andrewpillar/mgrt

Accidentally replied to the wrong thread on the list with this :/

-- 
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/f3abdba2-7e2b-4bdb-9054-b9694eb48445%40www.fastmail.com.


Re: [go-nuts] Re: Can’t get latest package version with modules

2019-10-01 Thread Andrew Pillar
>Thank you all. For schema migration i am looking for similar tool like flyway.

I created a simple migration tool called mgrt [1], which operates on pure SQL
scripts that are defined by the user. It has support for MySQL, SQLite and
PostgreSQL. Give it a try if you're looking for a simple migration tool that
just uses plain SQL under the hood. It's written in Go, so building it won't be
too hard.

[1] - https://github.com/andrewpillar/mgrt

-- 
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/51af693e-b999-41eb-8563-d199d7b5647e%40www.fastmail.com.


Re: [go-nuts] How to use .toml file to parse IP address and port to http server

2019-09-29 Thread Andrew Pillar
Use net.JoinHostPort to concatenate the values you have in the struct
and pass the to http.Server struct.

  if _, err := toml.Decode("config.toml", ); err != nil {
// handle error
  }

  addr, err := net.JoinHostPort(conf.Address, conf.PORT)

  if err != nil {
// handle error
  }

  src := {
Addr: addr,
  }

Be sure to set explicit struct tags on your destination struct that
will be used for unmarshalling the toml. This way the decoder will know
which struct fields to populate.

  type Config struct {
PORTstring `toml:"port"`
Address string `toml:"address"`
  }

This will only be necessary though if you want the fields to map
differently depending on their name.

-- 
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/594dc8061305a9d24a85bba3c403524eb4c9c637.camel%40andrewpillar.com.


Re: [go-nuts] Dependency injection in gorillamux handlers

2019-09-23 Thread Andrew Pillar
Why don't you use context.WithValue(r.Context(), , ) for passing
the injected values you want to your HTTP handlers. Then defer the logic for
retrieving whatever you want for that handler to a middleware function.

-- 
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/732f914e-e99d-4473-bafa-cf624e65af6d%40www.fastmail.com.


Re: [go-nuts] listen port auto allocation questions

2019-07-13 Thread Andrew Pillar
> How can i'm avoid  such errors and not specify ports by hand?
Perhaps you could use some kind of central store for storing the most
recently used port? Simply take that port from the store, increment it,
and place it back into the store for the next micro-service to use.

I think etcd [1], may be a good use case for this.

[1] - https://github.com/etcd-io/etcd


-- 
Andrew

-- 
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/9bd527fe88e87a4341b9efca7bba5eb32d1a9873.camel%40andrewpillar.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Some thoughts on query building in Go

2019-07-13 Thread Andrew Pillar
I put together a blog post exploring some of the approaches that could
be taken for idiomatic query building in Go. The Tl;DR of it is this:

First class functions are an idiomatic way of doing SQL query building
in Go. Check out the repository containing some example code I wrote
testing this out: https://github.com/andrewpillar/query.

I'd be interested in hearing what other people have to say with regards
to this subject matter.

https://andrewpillar.com/programming/2019/07/13/orms-and-query-building-in-go/

-- 
Andrew

-- 
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/8b47ed4c0cc1b5bccea6147878ad9e515909c8e7.camel%40andrewpillar.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Does the code have any concurrent problem?

2019-07-05 Thread Andrew Pillar
Have you tried building with the -race flag?

  go build - race

This should help you figure out any data race conditions that may occur.

-- 
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/1211e33f-f835-4d4f-bcc8-3fb1360ea4df%40www.fastmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Best ORM for Golang and their framework like Revel and Martini

2019-06-09 Thread Andrew Pillar

I made a comment about this on an HN thread about ORMs in Go.

> Personally I think an active record style ORM for Go like gorm is a 
poor fit for a language that doesn't come across as inherently OOP. 
Going through some of the documentation for gorm, it seems to rely 
heavily on method chaining which for Go seems wrong considering how 
errors are handled in that language. In my opinion, an ORM should be as 
idiomatic to the language as possible.


> I've used sqlx[1] before, and it feels pretty idiomatic to Go. You 
tag your structs with their respective database columns, write up a 
query, and hand it to sqlx to perform the deserialisation of the data. 
I've also come across squirrel[2] too, though I haven't used it, it does 
look rather interesting.


> [1] - https://github.com/jmoiron/sqlx

> [2] - https://github.com/masterminds/squirrel

I agree with you when you say that ORMs help with modeling relations. 
However I think the following the design of ActiveRecord is the wrong 
approach to take when it comes to ORMs in Go.


Also, regarding database migrations in Go. I made a simple tool for 
performing database migrations. It allows you to write plain SQL, and 
have these SQL scripts be performed against the database an logged. 
Right now it supports SQLite, MySQL, and PostgreSQL, you can find it at 
https://github.com/andrewpillar/mgrt.


--
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/e2191307-c64f-661e-54a5-d92a19d3390f%40andrewpillar.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Best ORM for Golang and their framework like Revel and Martini

2019-06-09 Thread Andrew Pillar
I made a comment about a similar topic on an HN thread, about 
ActiveRecord style ORMs in Go.


> Personally I think an active record style ORM for Go like gorm is a
> poor fit for a language that doesn't come across as inherently OOP.
> Going through some of the documentation for gorm, it seems to rely
> heavily on method chaining which for Go seems wrong considering how
> errors are handled in that language. In my opinion, an ORM should be
> as idiomatic to the language as possible.

> I've used sqlx[1] before, and it feels pretty idiomatic to Go. You tag
> your structs with their respective database columns, write up a 
query, > and hand it to sqlx to perform the deserialisation of the data. 
I've

> also come across squirrel[2] too, though I haven't used it, it does
> look rather interesting.

> [1] - https://github.com/jmoiron/sqlx

> [2] - https://github.com/masterminds/squirrel

You're right, ORMs do help with modelling data, but I think the 
ActiveRecord approach is the wrong way of going in regards to Go.


Also, regarding database migrations in Go, I made a simple migration 
tool for SQL migrations. You simply write plain SQL scripts, and these 
get performed and logged against the database. Right now it supports 
SQLite, MySQL, and PostgreSQL, and you can check it out here: 
https://github.com/andrewpillar/mgrt.


--
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/e269ee70-6a28-6437-dacd-ecac1d9760e4%40andrewpillar.com.
For more options, visit https://groups.google.com/d/optout.