Re: [go-nuts] Best practice for "main.go" to access members of a structure in the real package

2023-02-26 Thread Marcin Romaszewicz
Go doesn't have file scoped variables, only global variables and local variables declared in functions, so your "file" scope variables are global to their package. Global variables aren't inherently bad, that's a bit of voodoo that some ideological languages introduced, and people believe without

Re: [go-nuts] go get created directories with exclamation points

2023-01-04 Thread Marcin Romaszewicz
Go converts uppercase characters to the corresponding lower case character with an exclamation point in front of it to avoid case sensitivity collisions on case insensitive filesystems. In my pkg/mod/github directory, DataDog is the worst offender since it has changed capitalization over time, so

Re: [go-nuts] Unmarshal variable JSON structures

2022-12-26 Thread Marcin Romaszewicz
Here is an example of what I mean. https://go.dev/play/p/O6KIsxmSeaN This is why I wrote a code generator, it's tedious by hand :) On Mon, Dec 26, 2022 at 11:08 AM Marcin Romaszewicz wrote: > This is a very annoying problem, and one that we hit a lot in my project ( > https://gith

Re: [go-nuts] Unmarshal variable JSON structures

2022-12-26 Thread Marcin Romaszewicz
This is a very annoying problem, and one that we hit a lot in my project ( https://github.com/deepmap/oapi-codegen), where we generate Go models from OpenAPI specs, and the OpenAPI "AnyOf" or "OneOf" schema does precisely this. You can partially unmarshal; store your "type" field in a typed

Re: [go-nuts] Re: Encrypting credentials config file in production and pseudo key rotation

2022-10-01 Thread Marcin Romaszewicz
Check out SOPS, we use it to commit encrypted secrets into Git and only people with access to keys can see them. https://github.com/mozilla/sops On Sat, Oct 1, 2022 at 2:59 AM Peter Galbavy wrote: > We have a different requirement, which is opaquing of credentials in user > visible config

Re: [go-nuts] encoding/json doesn't find marshal/unmarshal via type aliases

2022-05-20 Thread Marcin Romaszewicz
ich has its own `UnmrshalJSON`, > which now gets promoted. > > So `Date.UnmsrshalJSON` calls your `UnmsrshalJSON` > `AliastedDate.UnmsrshalJSON` calls `AliastedDate.Time.UnmsrshalJSON` > > On Fri, May 20, 2022 at 3:14 PM Marcin Romaszewicz > wrote: > >> Sorry about mixin

Re: [go-nuts] encoding/json doesn't find marshal/unmarshal via type aliases

2022-05-20 Thread Marcin Romaszewicz
th the name B. What you have > is a type declaration > type A B > which creates a fully new type, with a new method set, but the same > underlying type as B. > > On Fri, May 20, 2022 at 9:28 AM Marcin Romaszewicz > wrote: > >> Hi All, >> >> I've

[go-nuts] encoding/json doesn't find marshal/unmarshal via type aliases

2022-05-20 Thread Marcin Romaszewicz
Hi All, I've created a simple struct that wraps time.Time because I'd like to unmarshal it differently from JSON than the default. It works great. However, when I pass a type alias of that struct to json.Marshal or json.Unmarshal, the MarshalJSON and UnmarshalJSON functions aren't invoked,

Re: [go-nuts] Slices of pointers or not?

2022-02-03 Thread Marcin Romaszewicz
It depends on what you do with it, and how you use it. []*Person is a slice of pointers, they're small. []Person is a slice of structs, they're bigger than pointers. The first requires a level of indirection to access, the second doesn't. The first requires no copying of structs when you're

Re: [go-nuts] Re: Best timeOut for mongoDB context timeout in golang

2022-01-16 Thread Marcin Romaszewicz
SQL Databases also typically have query timeouts on the DB side. When you cancel a context, the DB could still chug on that query for a while. For example, https://www.postgresql.org/docs/current/runtime-config-client.html (see statement_timeout). If you want to reliably cancel connections and not

Re: [go-nuts] From interface to []rune

2021-12-08 Thread Marcin Romaszewicz
No, you can't. A string is not a []rune, but it can be type converted to one, so you have to type convert your interface to string, then convert to runes. https://play.golang.com/p/GKITxGGYHZI On Wed, Dec 8, 2021 at 5:44 AM Денис Мухортов wrote: > Can i get data from interface to []rune like

Re: [go-nuts] nil

2021-12-02 Thread Marcin Romaszewicz
I updated your example with a couple of nil checks which work in this situation, so have a look after reading that nil error link above. https://go.dev/play/p/lsc72BWP-SO On Thu, Dec 2, 2021 at 1:17 AM Jan Mercl <0xj...@gmail.com> wrote: > On Thu, Dec 2, 2021 at 10:13 AM Денис Мухортов > wrote:

Re: [go-nuts] templates in html

2021-10-26 Thread Marcin Romaszewicz
Have a look at this: https://pkg.go.dev/html/template#Template.Funcs You need to provide a map of function names to function references to the template engine, otherwise, it has no idea what "stoneShop" is, because all it sees is an interface{} and has no context to know that it's a function.

Re: [go-nuts] Problem using embed in Go 1.16

2021-10-10 Thread Marcin Romaszewicz
If you're not directly using symbols from embed, import it with an _ alias, eg: import _ "embed" -- Marcin On Sun, Oct 10, 2021 at 9:12 AM Tong Sun wrote: > Hi, > > I'm having problem using embed with Go 1.16. I'm getting ether > > - //go:embed only allowed in Go files that import "embed" > -

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

2021-07-28 Thread Marcin Romaszewicz
I have this exact testing issue at my company, we have many Go services which use Postgres in production, but are unit tested against SQLite. The latest SQLite covers the vast majority of Postgres queries, so most tests simply use an SQLite in-memory DB. For the tests which require Postgres-

Re: [go-nuts] Go and GPUs

2021-06-25 Thread Marcin Romaszewicz
Graphics chips have a lot of proprietary IP, some of which the manufacturers would like to keep secret. If you see source for one of these drivers, you will have a good idea about the hardware organization, so they keep everything secret. It stinks for us developers who want to write cross

Re: [go-nuts] how break point work in multi-thread multi-core linux?

2021-06-10 Thread Marcin Romaszewicz
Threads are scheduled by the operating system, which has many syscalls to manage their execution status. When Delve hits an interrupt (trap) instruction for a breakpoint, it asks the OS to suspend all the other OS threads. Goroutine thread stacks are managed by Go, and Delve inspects all those

[go-nuts] Releasing a V2 module and interacting with git branches

2021-04-07 Thread Marcin Romaszewicz
Hi All, I need to release a V2 of my module. ( https://github.com/deepmap/oapi-codegen). I understand what to do on the Go side in terms of the /v2 suffix and go.mod changes, but I'm a little bit unclear how this works w.r.t git branches. Yes, I've looked at https://golang.org/ref/mod#vcs-find

Re: [go-nuts] Re: Alternate implementations of regular expression matching?

2021-04-01 Thread Marcin Romaszewicz
I have nothing useful to contribute to this discussion, however, I've been doing this long enough to remember Jamie Zawinski's quote about regular expressions :) Some people, when confronted with a problem, think "I know, I'll use > regular expressions." Now they have two problems. >

Re: [go-nuts] Can I import a package from a git submodule?

2021-03-31 Thread Marcin Romaszewicz
It's really annoying to deal with when you have private repositories, but try to simply `import RepoB/bar` from ModuleA, and don't bother with the submodule stuff. Module SHAs will replicate submodule functionality in a way that's more compatible with the language. On Wed, Mar 31, 2021 at 1:46 PM

[go-nuts] Question on module versioning expected behavior

2021-03-23 Thread Marcin Romaszewicz
I recently hit a little issue with go.mod versioning that's confusing me. My go.mod is straightforward: https://github.com/deepmap/oapi-codegen/blob/master/go.mod One of the packages in there is kin-openapi at v0.47.0: github.com/getkin/kin-openapi v0.47.0 We briefly had some code in the repo

Re: [go-nuts] running tests against benchmarks

2021-03-15 Thread Marcin Romaszewicz
What you want to do is common, but it's application-specific enough that there aren't so many generalized solutions. What I've always done is create a Go program which takes a while to run (I shoot for at least a minute) which runs your BeefyFunc in various ways that make sense to you, then I make

Re: [go-nuts] Golang Problems

2021-02-27 Thread Marcin Romaszewicz
We're not going to do your homework for you, but some things to consider: - maps are good at associating values with names - there's a strings.ToLower() function you will find useful - sort.Ints sorts ints in

Re: [go-nuts] Contrary to popular opinion...

2021-02-25 Thread Marcin Romaszewicz
Given the writing on the wall that GOPATH is going away, what I have done is created a single module where I keep all my own code, each different experiment in its own subdirectory. I named it "github.com/...", but never submitted it to github, so in the future I can do that without too much fuss

Re: [go-nuts] Data Structure in Go

2021-02-19 Thread Marcin Romaszewicz
What are you looking to learn about data structures? Data structures in Go work the same as in any other language conceptually, just the language syntax to implement the concepts will be different. One of the most commonly used books on data structures and algorithms is the Cormen, Leiserson,

Re: [go-nuts] R.I.P. Michael Jones

2021-02-04 Thread Marcin Romaszewicz
I will miss MTJ. I've worked with him on and off over 23 years, starting at Silicon Graphics, then as a customer when he founded Intrinsic Graphics, and finally in Google's GEO division. He was incredibly intelligent, a great teacher, and an extreme pedant :) RIP, Michael. -- Marcin On Thu, Feb

Re: [go-nuts] init() in package main won't run :-/

2021-01-12 Thread Marcin Romaszewicz
Your `var db=initDB()` runs before init(), and it returns an error, so the program aborts. Here's a change which initializes db explicitly in the init function, and it works as you expect: https://play.golang.org/p/xsUU2hfnx-w The init function is called after all variable initializations

Re: [go-nuts] sql string not interpolated as expected

2021-01-03 Thread Marcin Romaszewicz
Don't use fmt.Sprintf for the actual values, generate the positional arguments yourself. Something like: q := "SELECT x FROM t WHERE y IN (%s)" labelName := []string{'carnivore', 'mammal', 'vertebrate'} var arrayArgs []string for i := range labelName { arrayArgs = append(arrayArgs,

Re: [go-nuts] Generics - please provide real life problems

2020-12-23 Thread Marcin Romaszewicz
Those are simple examples of real world problems. I've been writing Go since the very beginning, having worked at Google when it was released and since I enjoy the language so much, I try to write all the backend server code in Go that I can. In these years, I've had to write many code generators

Re: [go-nuts] when do you use sync.Mutex instead of sync.RWMutex

2020-12-20 Thread Marcin Romaszewicz
Code using a simple sync.Mutex is also simpler, since you only have one way to lock and unlock and you don't have to think about lock type when writing code. In my opinion, use sync.Mutex, and if it proves to be inefficient, start investigating alternatives. In most cases, your simple code will

Re: [go-nuts] printing an empty slice with fmt.Printf()

2020-12-18 Thread Marcin Romaszewicz
It's expected behavior. Your for loop runs once for l=0, since your condition is <=0 because len([]byte{}) is 0. -- Marcin On Fri, Dec 18, 2020 at 3:28 PM Jochen Voss wrote: > Hello, > > I can print slices of bytes as hex strings, using code like the following: > > x := []byte{0, 1, 2, 3} >

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

2020-12-07 Thread Marcin Romaszewicz
It's uncommon to talk directly to a server these days, instead, we have proxies and load balancers along the way as well, and there are many reasons that a connection would get closed and you'd get an io.EOF. It's unlikely that the server received the request in this case, but it's possible,

Re: [go-nuts] Syntactic Sugar Idea for Go 2.0: until/unless, and postfix conditionals

2020-11-03 Thread Marcin Romaszewicz
Indeed! Go has while loops :) for { // do some stuff if !condition { break } } instead of { // do some stuff } while condition They are identical functionally, so why bother with the second syntax? You then get into arguments about which one to use. -- Marcin On Tue, Nov 3, 2020 at

Re: [go-nuts] Structs for JSON APIs and required fields... using pointers

2020-10-30 Thread Marcin Romaszewicz
I don't know if there's any standard practice to it. If the meaning of the zero value and "not present" is different in your application, then clearly, you can't use the zero value as you can't tell them apart, while you can with a pointer. The sql package does it with a version of optionals

Re: [go-nuts] Re: differentiate if a value was set or not

2020-10-23 Thread Marcin Romaszewicz
A concrete example of an "Optional" implementation in present in the sql package: https://golang.org/src/database/sql/sql.go?s=4943:5036#L178 In SQL, it's common to have "null" values be distinct from zero values, so the DB package has a struct with the value and a flag whether the value was

Re: [go-nuts] Any embedded scripting language for Go

2020-10-21 Thread Marcin Romaszewicz
Lua is probably your easiest bet: https://github.com/Shopify/go-lua On Tue, Oct 20, 2020 at 10:33 PM Aravindhan K wrote: > Hi, > > I am looking for a way to build interactive app,where user will be giving > instructions to draw as a script,rendering of the script will be displayed > live. > I

Re: [go-nuts] Golang slow performance inside for loop MySQL Queries

2020-10-21 Thread Marcin Romaszewicz
Can you connect to that DB any faster from the same machine not using Go? -- Marcin On Wed, Oct 21, 2020 at 3:43 AM Bill wrote: > Hello, > I created the sql to fetch all info in one call instead of multiple calls > per each row. > > One thing I noticed about golang is that when I ping my

Re: [go-nuts] Golang slow performance inside for loop MySQL Queries

2020-10-20 Thread Marcin Romaszewicz
Go's database layer is generally pretty quick, I use it a lot, but your code immediately sets off my DB alarms, because you are doing queries within the body of another query loop, which means you're opening up lots of connections, which could be slow. I'd reorganize as followd. - Cache the

Re: [go-nuts] net/http TLS issue

2020-10-16 Thread Marcin Romaszewicz
Having a passcode to protect a key file for a production service is pointless, because you move the problem of storing the certificate securely to the problem of storing the passcode securely, so might as well skip the passcode and store the cert securely. Your certificate is probably encoded as

Re: [go-nuts] ECDSA signature verification

2020-10-08 Thread Marcin Romaszewicz
ibrary. Just a quick question, do you > think calling C library from Go can give great results for 521 curve. > > > > On Thu, 8 Oct 2020, 21:03 Marcin Romaszewicz, wrote: > >> My issue was slightly different than yours, in that I was burning way too >> much CPU verifying

Re: [go-nuts] ECDSA signature verification

2020-10-08 Thread Marcin Romaszewicz
se it. >> >> Will check out the C library. Thanks >> >> >> >> On Wed, 7 Oct 2020, 22:22 Marcin Romaszewicz, wrote: >> >>> secp256r1 has been hand optimized for performance, the others haven't. >>> >>> If performance ther

Re: [go-nuts] ECDSA signature verification

2020-10-07 Thread Marcin Romaszewicz
secp256r1 has been hand optimized for performance, the others haven't. If performance there matters to you, it's actually faster to call out to C libraries to verify 384 and 512 bit curves. On Wed, Oct 7, 2020 at 9:27 AM Shobhit Srivastava wrote: > Hi All > > I have tried to do the performance

Re: [go-nuts] Re: Proper way of mocking interfaces in unit tests - the golang way

2020-10-05 Thread Marcin Romaszewicz
On Mon, Oct 5, 2020 at 10:31 AM Vladimir Varankin wrote: > > Or, it will be written as assert.Equal(got, want, > fmt.Sprintf("MyFunction(%v)", input)), but that is harder to write, and > therefore less likely to be written. > > That obviously depends on the implementation details but since we

Re: [go-nuts] Re: How to create UTC date without extra UTC string

2020-09-23 Thread Marcin Romaszewicz
See https://golang.org/pkg/time/#Time.Format Here's how to use it. I think this is exactly what you want: https://play.golang.org/p/3r0TFtOmtqF On Wed, Sep 23, 2020 at 11:43 AM Alex Mills wrote: > My guess, is that a starting place would be something like: > > > *var s =

Re: [go-nuts] Cross compiling for linux from dawin

2020-09-22 Thread Marcin Romaszewicz
Your compiler environment for C code is still building for Darwin, most likely. You need to set up a cross compiler and use cgo ( https://golang.org/cmd/cgo/). $CC should invoke your cross compiler. On Tue, Sep 22, 2020 at 11:19 AM Mixo Ndleve wrote: > Experiencing this problem when

Re: [go-nuts] database/sql doesn't return error for query-string-destination if NULL bug or feature

2020-09-11 Thread Marcin Romaszewicz
Which sqlite driver are you using? That sounds like a bug. On Fri, Sep 11, 2020 at 10:56 AM Stephan Lukits wrote: > I passed a string-type pointer (as last destination) to a sql.DB.Query > call which had a NULL value as field value. No error was returned and all > other fields got the

Re: [go-nuts] Workflow and tools for JSON Schema generation

2020-09-04 Thread Marcin Romaszewicz
, and less convoluted. V1 was a learning experience. On Fri, Sep 4, 2020 at 10:56 AM Marcin Romaszewicz wrote: > Have you considered reversing the workflow? You write the OpenAPI spec, > and have a code generator produce the Schemas and server boilerplate? > > If that's ok, check ou

Re: [go-nuts] Workflow and tools for JSON Schema generation

2020-09-04 Thread Marcin Romaszewicz
Have you considered reversing the workflow? You write the OpenAPI spec, and have a code generator produce the Schemas and server boilerplate? If that's ok, check out my project :) https://github.com/deepmap/oapi-codegen We successfully use it for many API's in production. -- Marcin On Thu,

Re: [go-nuts] Re: Share GOMODCACHE between unix users

2020-08-19 Thread Marcin Romaszewicz
Yes, each user would populate their own module cache locally if using your own proxy. On Wed, Aug 19, 2020 at 10:04 AM wilk wrote: > On 19-08-2020, Marcin Romaszewicz wrote: > > --71f06b05ad3dc9f8 > > Content-Type: text/plain; charset="UTF-8" > > &g

Re: [go-nuts] Share GOMODCACHE between unix users

2020-08-19 Thread Marcin Romaszewicz
I have many users building Go at my company, and instead of sharing the module cache on the filesystem, a much better approach is to use a caching module proxy, such as Athens (https://github.com/gomods/athens). See the documentation for the GOPROXY environment variable. -- Marcin On Wed, Aug

Re: [go-nuts] Pipe multiple commands in golang

2020-08-12 Thread Marcin Romaszewicz
You have two options here. One, is you execute a shell, and just tell the shell to run your command, eg bash -c "strings dynamic_file_path | grep regex". The other option is that you exec strings and grep independently, and connect the two of them using an os.pipe, but it's a lot more work to do

Re: [go-nuts] Re: Quick question about calling Set-Cookie twice in a row

2020-07-14 Thread Marcin Romaszewicz
The Go http code calls Header.Add() on your cookie, and Header.Add will concatenate values together. If you want replacement semantics, you'll have to clearout the "Set-Cookie" header on the response, or only add your final cookie. On Tue, Jul 14, 2020 at 4:58 PM B Carr wrote: > In my

Re: [go-nuts] What can cause a process launched via os.exec to sporadically die from SIGPIPE

2020-07-06 Thread Marcin Romaszewicz
Thanks for the tip, I wasn't aware that happened! I'll use os.Pipe. -- Marcin On Mon, Jul 6, 2020 at 4:45 PM Ian Lance Taylor wrote: > On Mon, Jul 6, 2020 at 4:42 PM Marcin Romaszewicz > wrote: > > > > Yes, I am using io.Pipe, and passing in the PipeWriter side of it as &

Re: [go-nuts] What can cause a process launched via os.exec to sporadically die from SIGPIPE

2020-07-06 Thread Marcin Romaszewicz
:14 PM Marcin Romaszewicz > wrote: > > > > On Sun, Jul 5, 2020 at 1:05 PM Ian Lance Taylor wrote: > >> > >> On Sun, Jul 5, 2020 at 10:54 AM Marcin Romaszewicz > wrote: > >> > > >> > I'm hitting a problem using os.exec Cmd.Start to run a process

Re: [go-nuts] What can cause a process launched via os.exec to sporadically die from SIGPIPE

2020-07-05 Thread Marcin Romaszewicz
On Sun, Jul 5, 2020 at 1:05 PM Ian Lance Taylor wrote: > On Sun, Jul 5, 2020 at 10:54 AM Marcin Romaszewicz > wrote: > > > > I'm hitting a problem using os.exec Cmd.Start to run a process. > > > > I'm setting Cmd.Stdio and Cmd.Stderr to the same instance of an io

[go-nuts] What can cause a process launched via os.exec to sporadically die from SIGPIPE

2020-07-05 Thread Marcin Romaszewicz
Hi All, I'm hitting a problem using os.exec Cmd.Start to run a process. I'm setting Cmd.Stdio and Cmd.Stderr to the same instance of an io.Pipe, and spawn a Goroutine to consume the pipe reader until I reach EOF. I then call cmd.Start(), do some additional work, and call cmd.Wait(). The runtime

Re: [go-nuts] [generics] Thank you Go team

2020-06-18 Thread Marcin Romaszewicz
I'd like to add a big +1 here. The proposal around contracts and generics is solid from a conceptual perspective, and I enjoyed reading the rationale behind what's supported, and what isn't, and I think this is a wonderful addition to the language which keeps type safety in a very Go-like way

Re: [go-nuts] Best practice for Database Open and Close connection

2020-05-27 Thread Marcin Romaszewicz
Behind the scenes, DB is actually a connection pool, not a single connection, which will open new connections when you need them. In our services - which do a LOT of DB work, we only open a single sql.DB connection and share it among all our handlers. Whenever a handler does a db.Whatever, the db

Re: [go-nuts] Get name of struct implementing interface using interface method, reflection

2020-05-08 Thread Marcin Romaszewicz
Go isn't polymorphic, whenever your String() function is called, it's on BaseFoo, you have to do it like this: https://play.golang.org/p/69rw0jRPalz On Fri, May 8, 2020 at 1:43 PM Glen Newton wrote: > Thanks! > > Oh no, when I try that here: https://play.golang.org/p/RV-S4MJWYUi > Did not

Re: [go-nuts] Re: recommended approach for loading private keys requiring passwords

2020-05-02 Thread Marcin Romaszewicz
Haha, great minds think alike, as they say. One of my colleagues (from a cloud security company) wrote basically the same thing in Go: https://github.com/cloudtools/ssh-cert-authority There's also a really fantastic product that works via signed SSH certs called Teleport

Re: [go-nuts] Is this a safe way to block main thread but not main goroutine?

2020-04-29 Thread Marcin Romaszewicz
As Thomas said, this will work for sure, though, and doesn't require any manual setup, and you don't need to do funny business with CGO. func main() { go doAllYourOtherStuff() blockOnDarwinEventLoop() } Done. On Wed, Apr 29, 2020 at 1:44 PM Akhil Indurti wrote: > I want to mirror (or

Re: [go-nuts] Json Parse Data [unexecpted non whitespace 1 to 28]

2020-04-28 Thread Marcin Romaszewicz
Ali, your example has several problems. First, you do this: var p Person data, err := json.Marshal(p); if err != nil{ fmt.Println("Error", err) } What this does is encode an empty object, that's fine. Next, you read the HTTP body from the request, and try to unmarshal that.

Re: [go-nuts] Appending to a slice of an array on the stack

2020-04-18 Thread Marcin Romaszewicz
I added a little more to your example to illustrate my email points. https://play.golang.org/p/eT5tKUniC1E 1) stack_array may or may not be on the stack, Go makes that choice. 2) slice := stack_array[:] Doesn't copy the data, it creates a slice structure which wraps it. 3) Next, when you call

Re: [go-nuts] Any reason why this type conversion is not allowed?

2020-04-13 Thread Marcin Romaszewicz
Go doesn't do any implicit type conversions, and it's quite consistent about that. The only things which are type "converted" are untyped constants. I would love for this to work too, by the way, since I often come up with something like: var a []interface{} var b []SomethingConcrete I would

Re: [go-nuts] If in doubt prefer to wrap errors with %v, not %w?

2020-03-22 Thread Marcin Romaszewicz
In my opinion, this is a much nicer errors package than Go's library, and I've been using it everywhere: https://github.com/pkg/errors Instead of fmt.Errorf("%w"), you do errors.Wrap(err, "message"), and errors.Unwrap(...) where you want to inspect the error. It's much more explicit and less

Re: [go-nuts] How to break-out of martini middleware

2020-03-15 Thread Marcin Romaszewicz
Martini is defunct, but Gin took their torch and ran with it. I use such http routing frameworks as part of my day job, and would recommend the three following ones. 1) Echo (https://github.com/labstack/echo) 2) Gin (https://github.com/gin-gonic/gin) 3) Chi (https://github.com/go-chi/chi) I would

Re: [go-nuts] Using modules with private repos

2020-03-11 Thread Marcin Romaszewicz
There is really no nicer way. You do not have to make those .insteadOf overrides in your global git config, though, you can do it in the local git config for your Go repository to contain the damage. You will also find that private repositories don't work nicely with things like the Athens module

Re: [go-nuts] how to design log package to avoid allocations

2020-03-09 Thread Marcin Romaszewicz
I'm using Uber's zap logger in production systems ( https://github.com/uber-go/zap). It is designed to emit structured JSON logs and do the minimal amount of allocations possible. It's a completely different interface from Go's log package, but that is where the efficiency comes from. I'd highly

Re: [go-nuts] Go without garbage collector

2020-02-12 Thread Marcin Romaszewicz
Your paper proves your conclusions given your assumptions :) When there is no GC runtime in a language, you are open to managing memory however you see fit, and there are lots of models which are more efficient than reference counted smart pointers or whatever. I've worked on many realtime systems

Re: [go-nuts] Why Discord is switching from Go to Rust

2020-02-07 Thread Marcin Romaszewicz
eers time is spent writing the initial code and tests. With Java, most of their time is spent chasing Java memory allocation issues. I think the place the effort goes speaks volumes about how well the GC works in both languages. > On Feb 7, 2020, at 12:57 PM, Marcin Romaszewicz wrote: > >  &

Re: [go-nuts] Why Discord is switching from Go to Rust

2020-02-07 Thread Marcin Romaszewicz
You're not oversimplifying. GC incurs a price, and that's performance. If you have a program which manages its own memory optimally for its usage pattern, it will be more efficient than a generic GC that has to handle all usage patterns. I use Go everywhere I can, since the tradeoff between

Re: [go-nuts] Question about 'import' statement

2020-02-03 Thread Marcin Romaszewicz
All the files get downloaded to your $GOPATH/src or $GOPATH/pkg, depending on whether modules are enabled. Everything gets compiled together into the same static executable, so yes, the files get compiled. The order of imports should not matter in well written code, but you can always create

Re: [go-nuts] [Proposal] database/sql: add interface that unite DB and Tx

2020-01-16 Thread Marcin Romaszewicz
I have that exact interface in all of my DB code, and I never use sql.Tx or sql.DB directly. You don't need Go's libraries to adopt this at all, just use your own. On Wed, Jan 15, 2020 at 11:20 PM Mhd Shulhan wrote: > ## Problem > > At some point we have a function that receive an instance of

Re: [go-nuts] types lookup for error interface type

2019-12-14 Thread Marcin Romaszewicz
Error is an interface, so its type depends on the implementation satisfying that interface. You can't just create an "error", since they don't exist, all that exists are implementation satisfying the error interface. That's what you're doing with NewSignature. Could you just create an

Re: [go-nuts] How to mock structs with interdependent interface methods?

2019-12-12 Thread Marcin Romaszewicz
I face similar problems in a lot of production Go code which I write. I do have an answer for this, but it's not pretty. Your code would look something like this: type ResourceGetter interface { GetResource(id string) (*Resource, error) } type ResourceManagerImpl struct { rg ResourceGetter

Re: [go-nuts] How to have fixed xml attributes "Header"

2019-12-12 Thread Marcin Romaszewicz
et me know your thoughts > > Thanks > > On Thu, Dec 12, 2019 at 6:14 PM Marcin Romaszewicz > wrote: > >> Could you share your code which isn't working? >> >> Here's a simple example of how you would do something like that, but not >> knowing your code,

Re: [go-nuts] How to have fixed xml attributes "Header"

2019-12-12 Thread Marcin Romaszewicz
Could you share your code which isn't working? Here's a simple example of how you would do something like that, but not knowing your code, it might not be helpful. https://play.golang.org/p/H-9eCTYJxTA On Thu, Dec 12, 2019 at 9:57 AM paresh patil wrote: > Hi, > > > I'm new to Go and finding

Re: [go-nuts] Re: Where is the middle of Brazil?

2019-12-07 Thread Marcin Romaszewicz
As a bonus challenge, try to compute the population center of Brazil :) One way of finding the center is minimizing the integral of all distances to a point, but for population, these points now have weight. Like Michael above, I spent years working on Google Earth, and the code running in the

Re: [go-nuts] Разбить массив чисел на два массива

2019-12-01 Thread Marcin Romaszewicz
re Engineer > github.com/danicat > twitter.com/danicat83 > > > Em dom., 1 de dez. de 2019 às 17:07, Marcin Romaszewicz > escreveu: > >> It's very simple to do that: >> https://play.golang.org/p/1i7pI2OXmej >> >> >> >> On Sun, Dec 1, 2019 at 8:22

Re: [go-nuts] Разбить массив чисел на два массива

2019-12-01 Thread Marcin Romaszewicz
It's very simple to do that: https://play.golang.org/p/1i7pI2OXmej On Sun, Dec 1, 2019 at 8:22 AM Vital Nabokov wrote: > Разбить массив чисел на два массива? > Split an array of numbers into two arrays? > > -- > You received this message because you are subscribed to the Google Groups >

Re: [go-nuts] Is anyone aware of a blocking ring buffer implementation?

2019-11-23 Thread Marcin Romaszewicz
e problem. > > On Nov 21, 2019, at 11:18 PM, Marcin Romaszewicz > wrote: > >  > I am in fact replacing an io.Pipe implementation, because I need to buffer > some data. io.Pipe doesn't buffer, it just matches up read and writes with > each other. > > What I'm effect

Re: [go-nuts] Is anyone aware of a blocking ring buffer implementation?

2019-11-21 Thread Marcin Romaszewicz
ation though). > > > On Nov 21, 2019, at 10:20 PM, Dan Kortschak wrote: > > > > There is this: https://godoc.org/bitbucket.org/ausocean/utils/ring > > > > It has been used in production fairly extensively. > > > >> On Thu, 2019-11-21 at 19:47 -0800, Marcin

[go-nuts] Is anyone aware of a blocking ring buffer implementation?

2019-11-21 Thread Marcin Romaszewicz
Hi All, Before I reinvent the wheel, and because this wheel is particularly tricky to get right, I was wondering if anyone was aware of a a library providing something like this - conforms to io.Reader - conforms to io.Writer - Contains a buffer of fixed size, say, 64MB. If you try to write when

Re: [go-nuts] Re: [64]byte()[:]

2019-11-16 Thread Marcin Romaszewicz
It's not even worth calling bytes.Equal to see if a bunch of bytes is zero. A more efficient way would be to simply loop over them and check for non-zero. -- Marcin On Sat, Nov 16, 2019 at 4:00 PM Kevin Malachowski wrote: > "make"ing a byre slice every time you call Equal is not likely as >

Re: [go-nuts] Re: An old problem: lack of priority select cases

2019-10-04 Thread Marcin Romaszewicz
What he's trying to say is that it is pointless to order select cases in this example, because it is impossible to guarantee ordering in an asynchronous system. You have two asynchronous data streams, ctx.Done() and "v", in that example above. Generally, those select cases will happen one by

Re: [go-nuts] ent: an entity framework for Go

2019-10-03 Thread Marcin Romaszewicz
That looks very nice, congrats! I like that it's simple and doesn't try to solve every problem, just simple relationships, so you can solve most of your simple DB schema needs (and most DB usage is quite simple in most services). Do you have any plans to add a Postgres driver? -- Marcin On Thu,

Re: [go-nuts] go 1.13 won't compile

2019-09-30 Thread Marcin Romaszewicz
in go that I use for myself. I >>>>> put it in https://play.golang.org/p/U7FgzpqCh-B >>>>> >>>>> It compiles and runs fine on go 1.12.x under linux, and fine on go >>>>> 1.13 under windows 10. I have not yet installed go1.13.1 on my windows 10 >>&g

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

2019-09-28 Thread Marcin Romaszewicz
I've used naked SQL, and ORMs (Django in Python, Hibernate and EBean in Java, GORM in Go) for years, and I've noticed the following: 1) It's really easy to write very inefficient queries in an ORM. If you have a very simple 1:1 mapping between tables and objects, it's fast, efficient, easy to

Re: [go-nuts] go 1.13 won't compile

2019-09-28 Thread Marcin Romaszewicz
What was the last version of Go which worked for you? "dsrt" isn't a valid module path in the new module resolution code. Does it work if you disable modules - "GO111MODULE=off go install dsrt"? On Sun, Sep 22, 2019 at 9:56 AM rob wrote: > Hi. I think I'm having an issue compiling my code

Re: [go-nuts] nil map assignment panics. can we do better?

2019-09-24 Thread Marcin Romaszewicz
Could we have an operation like append() for slices? How about: m := insert(m, "key", "value"). It returns m unchanged if it's allocated, otherwise, it allocates. We're already familiar with this kind of function. -- Marcin On Mon, Sep 23, 2019 at 10:58 PM abuchanan via golang-nuts <

Re: [go-nuts] Need a Modules for Dummy's Guide. Please help

2019-09-23 Thread Marcin Romaszewicz
I've beat my head into the module wall a bit as well, and while I don't understand some of the design decisions, I've done my best to answer your questions inline. On Mon, Sep 23, 2019 at 1:42 PM Stuart Davies wrote: > Hi. > > > > I have been using GO for about a year and I love the language

Re: [go-nuts] sqlserver error "TLS Handshake failed: x509: certificate signed by unknown authority"

2019-09-10 Thread Marcin Romaszewicz
You're missing the CA Root certificates for whatever linux distribution is running your application. For example, I use Alpine linux as my Docker base image for my Go services, and I must install the certificates like this via the Dockerfile: RUN apk update && apk add ca-certificates Find the

Re: [go-nuts] How to do a forward compatibility support for go 1.13?

2019-09-06 Thread Marcin Romaszewicz
This may not be the exact answer you're looking for, but there's a package which handles this even better than Go's builtin error package: https://github.com/pkg/errors Dave Cheney's package is better designed, IMO, and the explicit errors.Wrap() call is more clear than inferring it from your

Re: [go-nuts] ticker not firing often enough in minimal mac app with run loop

2019-09-04 Thread Marcin Romaszewicz
I'm not quite sure how to avoid this, but I'm pretty sure that I know the cause. Read up on Grand Central Dispatch and Centralized Task Scheduling ( https://developer.apple.com/library/archive/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/DiscretionaryTasks.html). It's been

Re: [go-nuts] Re: An old problem: lack of priority select cases

2019-08-28 Thread Marcin Romaszewicz
Think of a channel as existing for the lifetime of a particular data stream, and not have it be associated with either producer or consumer. Here's an example: https://play.golang.org/p/aEAXXtz2X1g The channel here is closed after all producers have exited, and all consumers continue to run

Re: [go-nuts] Re: Running tests per package with Go module

2019-08-20 Thread Marcin Romaszewicz
It could fail if you're under $GOPATH and GO111MODULE=auto, since inside the GOPATH, auto=off -- Marcin On Tue, Aug 20, 2019 at 12:43 PM Jacques Supcik wrote: > Hello Chris, > > I made a small project with the same structure as yours to reproduce the > problem :

Re: [go-nuts] panic: interface conversion: interface is nil, not encoding.BinaryUnmarshaler

2019-08-14 Thread Marcin Romaszewicz
Here you go: https://play.golang.org/p/_cPmaSxRatC You want to unmarshal into , not into This means: var duck2 A not: var duck2 Duck On Wed, Aug 14, 2019 at 8:46 AM Jochen Voss wrote: > Hello, > > I'm trying to read gob-encoded data into a variable of interface type. In > simple cases,

Re: [go-nuts] Module can't find itself

2019-07-25 Thread Marcin Romaszewicz
Thanks, and duh :) I was so busy trying to figure out why it wasn't building that I neglected to check the basics. -- Marcin On Wed, Jul 24, 2019 at 9:31 PM Burak Serdar wrote: > On Wed, Jul 24, 2019 at 10:11 PM Marcin Romaszewicz > wrote: > > > > Hi All, > > >

[go-nuts] Module can't find itself

2019-07-24 Thread Marcin Romaszewicz
Hi All, I've got a module problem which I don't quite understand. All my code is here: https://github.com/deepmap/oapi-codegen When I run "go build" from the top of the repo, I get: $ go build can't load package: package github.com/deepmap/oapi-codegen: unknown import path

Re: [go-nuts] Re: prevent alteration of binaries once distributed in the wild?

2019-07-23 Thread Marcin Romaszewicz
Don't be too afraid of governments tampering with your program, I mean this in the best possible way, but you are nobody important enough :) Governments issue subpoenas, arrest warrants, and issue court orders - that's much quicker and more effective than hacking. In the security space, we also

  1   2   >