[go-nuts] Local mod version

2021-03-19 Thread Pierre Curto
Hello gophers, Trying to locally get the same semver string as if downloading it from its git repo, and not succeeding. Any pointer? Thanks! -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving

Re: [go-nuts] Re: stringer command and generated String() function

2020-02-18 Thread pierre . curto
> I did not add it since it was not the original question ^^ > But why can't we have the check and a switch? > > Definitely can. Just didnt see it. My response was somewhat tangential to your question, sry. -- You received this message because you are subscribed to the Google Groups

[go-nuts] Re: stringer command and generated String() function

2020-02-18 Thread pierre . curto
The const/slice implementation should be faster as Jan said. Note that there is also a blank function that fails at compile time if items have been added or changed and stringer has not been rerun since. The const/slice implementation allows for that (useful!) check. Le mardi 18 février 2020

[go-nuts] map memory usage

2020-01-31 Thread pierre . curto
Hello, Is there a better way to estimate the memory usage of a map, other than the following: https://play.golang.org/p/MLSd84CJB3R Thanks! -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving

[go-nuts] Re: Convert a charAtIndex of string to ASCII equivalent int value

2019-12-21 Thread pierre . curto
You can do something like this: https://play.golang.org/p/J7-N8_UDlL8 Le samedi 21 décembre 2019 17:23:28 UTC+1, Amarjeet Anand a écrit : > > Hi > I have a set of strings(ASCII), that i want to assign to a string array(of > cap 128). > The position of the string in the array is decided by the

[go-nuts] Re: Workaround for missing RWMutex.Try*Lock()

2019-12-04 Thread pierre . curto
This may be of relevance to you: https://pkg.go.dev/gvisor.dev/gvisor/pkg/tmutex?tab=doc Le mercredi 4 décembre 2019 01:21:41 UTC+1, Liam a écrit : > > I have a problem that is trivially solved via > > door sync.RWMutex > > func Reader() T { >if !door.TryRLock() { // missing in stdlib :-( >

[go-nuts] Re: On the topic of try() and errors

2019-07-10 Thread pierre . curto
Interesting reasoning Michael... Le mercredi 10 juillet 2019 01:46:03 UTC+2, Michael Jones a écrit : > > In the hope of elevating the discussion of late, I've made a little speech > as one might do at a lunchtime discussion with students or colleagues. > Maybe this will make sense to some

Re: [go-nuts] The "leave "if err != nil" alone?" anti-proposal

2019-06-30 Thread pierre . curto
Indeed. I think many people like the proposal but are not vocal about it. It is not perfect but it *does *bring value to the table if you read the proposal in its entirety and think about how you would use/could use it in a real life scenario. I do *decorate *errors a lot, I do care about the

[go-nuts] Re: io.Copy and Writer

2019-05-21 Thread pierre . curto
Hello, Indeed, you need to flush the bufio.Writer for the remaining data to be sent accross. Usually though, you do not need to buffer the input or output at all. In which case, the code is straight forward: https://play.golang.org/p/F1tMKdsapyX If you do need to buffer though, I would do

Re: [go-nuts] bool in go/ast.filterParamList

2019-05-13 Thread pierre . curto
Got it, thank you. -- 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

[go-nuts] bool in go/ast.filterParamList

2019-05-13 Thread pierre . curto
Hello, While studying the go/ast package, I stumbled upon the following: https://golang.org/src/go/ast/filter.go#L140 Unless I am missing something, shouldnt this just be: https://play.golang.org/p/uQJ3XtEcgWE ? Thanks. -- You received this

[go-nuts] Merging package files

2019-05-10 Thread pierre . curto
Hello, I was wondering if there was an easy way to merge package files into a single one, like the bundle tool does but as a library. My goal is to take a package, transform some of its types (change their name) and output a file which

[go-nuts] Re: module exports

2018-11-08 Thread pierre . curto
If you want to hide packages that you use only for your main package, then put them under the internal directory within your main package. That way, they are still available from your main package (or any sub package) but not outside of it, including in godoc. i.e. top/ top.go

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

2018-05-23 Thread pierre . curto
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

[go-nuts] Re: Parsing a CSV column with partially double-quotes in it

2017-09-29 Thread pierre . curto
Because this is invalid csv. Should be: This\t"""is"" no"\tfun If you still need to parse it, then write your own parser that handles it, for instance using a bufio.Reader. Le jeudi 28 septembre 2017 22:56:27 UTC+2, Lantos István a écrit : > > > I want to parse the following CSV structure. The

[go-nuts] Re: Struct overloading method issue

2017-09-01 Thread pierre . curto
Maybe I misunderstood your need, but I would just call the A method directly like below. type A struct{} func (a *A) private() {} func (a *A) Public() { a.private() } type B struct {A} func (b *B) private() { b.A.private() } bi := B{} b.Public() //calls the A.Private Le vendredi 1

[go-nuts] Re: API patterns for a function with a single argument that is rarely needed

2017-07-07 Thread pierre . curto
Hello, I personally like the variadic version, which is very well described here and here . Le vendredi 7 juillet 2017 17:18:14

[go-nuts] Re: golang regex question

2017-06-02 Thread pierre . curto
Hello, Try something like this: https://play.golang.org/p/xSEX1CAcQE Le vendredi 2 juin 2017 16:26:24 UTC+2, Sankar a écrit : > > 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,

[go-nuts] Re: Concurrent access to map

2017-05-15 Thread pierre . curto
Hello, Once you have written out your values to the map, you can read them concurrently and safely. If you need to write again to it (insert or delete), then you must ensure it is done safely. Note that, from what I can see in tip, in 1.9 there will be a safe concurrent map:

[go-nuts] Re: Why a []interface{} containing 2 different interface should use function like this?

2017-05-05 Thread pierre . curto
Since S1 and S2 satisfy the Stringl interface just use that for your slice type and you get something like (note that you do not need to specify the variables types if you initialize them like you did). https://play.golang.org/p/pJHU0Dq8t6 Le vendredi 5 mai 2017 13:35:42 UTC+2, eZio Pan a

[go-nuts] Re: bug or not?

2017-05-03 Thread pierre . curto
RHS = right hand side LHS = left hand side Le mercredi 3 mai 2017 14:53:40 UTC+2, mhh...@gmail.com a écrit : > > similarly, it is possible to rewrite len, or a package id. > > I got caught some times about that, > since then i take care about that. > > but yeah, feels weird. > > btw, what means

[go-nuts] Re: encoding/json: unexpected behaviour when unmarshalling into struct with interface{} field

2017-05-02 Thread pierre . curto
Hello, My guess: If you dont pass in a pointer, then you pass a value. What would be the point of updating the value that you will never see and that will get discarded? Hence it returns a map that provides the unmarshaled values so at least you have something to work with. Le mardi 2 mai 2017

[go-nuts] Re: Oracle db and panics on interrupt

2017-04-28 Thread pierre . curto
Hello, Thanks a lot indeed, I did not know about those. I still get crashes on OSX besides the variables being read by the OCI libs (traces shows they are). The other thing is that when this happens, the process goes into an infinite loop spitting "fatal: morestack on g0" for ever, and kill

[go-nuts] Oracle db and panics on interrupt

2017-04-26 Thread pierre . curto
Hello, I am unsure where to log the following issue: whenever I send an interrupt signal to a go process running an Oracle query, it panics with either "fatal: morestack on g0" or "fatal error: runtime: stack split at bad time". A sample code reproducing the issue is here

Re: [go-nuts] [ANN] sqlite

2017-04-21 Thread pierre . curto
This looks really interesting... I also saw a similar idea with a different approach: https://github.com/elliotchance/c2go. Le vendredi 21 avril 2017 16:38:38 UTC+2, Andy Balholm a écrit : > > As near as I can tell, this is an intermediate step in a project whose > ultimate goal is to compile

[go-nuts] Re: How to set value to empty interface{}

2017-04-11 Thread pierre . curto
In Go, everything is passed by value, including interfaces (empty or not). A quick overview at http://goinbigdata.com/golang-pass-by-pointer-vs-pass-by-value/. So, you cannot change the value pointed to by an interface unless you "unbox" it: https://play.golang.org/p/uzccweBdzV Further

[go-nuts] Re: How to set value to empty interface{}

2017-04-11 Thread pierre . curto
Either pass around the pointer to your struct or use a dedicated interface to alter the struct contents. Examples of each here and there . Le mardi 11 avril 2017 15:22:41 UTC+2, Th3x0d3r a écrit : > > Hey there ! > >

[go-nuts] Re: Best way to save users input data that could be used later?

2017-03-21 Thread pierre . curto
Hello, You keep appending json objects to your file, which produces invalid json after the first item. You either need to produce valid json, for instance by putting your items into an array, or use a streaming json parser that parses items individually. I have changed your example to perform

[go-nuts] Re: Aren't package declarations (and per file imports) redundant?

2017-03-19 Thread pierre . curto
Besides what has been said, another use for the package declaration is being able to declare "main" programs that are ignored at build time but used by go generate within the package. A good example of this is in the gob package: https://golang.org/src/encoding/gob/dec_helpers.go is generated

[go-nuts] Re: Variadic parameters to SQL-queries, specifically gopkg.in/rana/ora.V*

2017-02-24 Thread pierre . curto
Yes you can, use append: https://golang.org/ref/spec#Appending_and_copying_slices Le vendredi 24 février 2017 17:09:12 UTC+1, Trond Kandal a écrit : > > Thank You very much, Sir! > > That did the trick! > I am not used to the small and subtle tricks of Go yet. > > Is there any way I can append

[go-nuts] Re: Variadic parameters to SQL-queries, specifically gopkg.in/rana/ora.V*

2017-02-24 Thread pierre . curto
Do a: rst, err := stmt.Qry(params...) The 3 dots will expand the slice for the variadic function. Le vendredi 24 février 2017 16:05:42 UTC+1, Trond Kandal a écrit : > > Thank Your for your answer, Sir! > > Hmmm... > I do not seem to get it working > > sqlQry := "SELECT * FROM TIA_EMNEINFO

Re: [go-nuts] Reading an .ini file

2017-01-30 Thread pierre . curto
Hello, When this thread came up I was working on an ini formatting tool, similar to (but way simpler than) gofmt, which required parsing and manipulating the contents of an ini file. As you have found out, there are a bunch of packages already doing that, but not in the spirit of simplicity

Re: [go-nuts] Re: Idiomatic way to reference custom error codes

2017-01-26 Thread pierre . curto
Le jeudi 26 janvier 2017 07:42:55 UTC+1, JohnGB a écrit : > > Thanks Pierre, that looks like a simple and quite clean implementation. > Although it's easier to use an iota for the numbering, does that open up > any issues with keeping the documentation up to date? I know it's easier > to

[go-nuts] Re: Idiomatic way to reference custom error codes

2017-01-25 Thread pierre . curto
Maybe use a map along the lines of: https://play.golang.org/p/YDF4q6cTyX ? Le mercredi 25 janvier 2017 18:16:33 UTC+1, JohnGB a écrit : > > I have an HTTP API written in Go, and to give more fine grained responses > to the client app, we return our own error codes along with the standard > HTTP

[go-nuts] Re: Why is src modified when concatenating slices with dst = append(dst, src[:i])

2016-11-19 Thread pierre . curto
Hello and welcome to Go! It will all make sense after reading this: https://blog.golang.org/go-slices-usage-and-internals I leave you to find the solution once you have read the article :). Hint: It indeed has to do with the backing array of the slice. In step1 you are creating a new slice for

[go-nuts] Re: Exported singleton in vendor is initialized on every call

2016-11-14 Thread pierre . curto
Hello, You shadow your DB global variable in the DB, err := gorm.Open() call. Do something like this instead: var err error DB, err = gorm.Open() Le lundi 14 novembre 2016 09:54:40 UTC+1, Rayland a écrit : > > Greetings fellow gophers, > > I have a library in my vendor folder that looks like

[go-nuts] Re: JSON parser

2016-11-10 Thread pierre . curto
Then you need to provide sample data... Le jeudi 10 novembre 2016 18:33:10 UTC+1, Sergio Hunter a écrit : > > I agree with you) But what do i do with this, It's exactly the same error. > > четверг, 10 ноября 2016 г., 19:05:12 UTC+2 пользователь > pierre...@gmail.com написал: >> >> We will get

[go-nuts] Re: JSON parser

2016-11-10 Thread pierre . curto
Sorry, I did not test it. This one passes the playground build (up to the mysql driver not being found): https://play.golang.org/p/_WfTMOd-s6 Le jeudi 10 novembre 2016 17:13:19 UTC+1, Sergio Hunter a écrit : > > The compiler generates an error > > Test.go:71: undefined: o > Test.go:85: cannot

[go-nuts] Re: JSON parser

2016-11-10 Thread pierre . curto
Ok, then something along those lines: https://play.golang.org/p/dMPQIrEdNN Le jeudi 10 novembre 2016 16:36:21 UTC+1, Sergio Hunter a écrit : > > Thanks so much for your answer. > I'll try to explain what I need. I have a field "data",inside field has > compress rows and text data(json), I need

[go-nuts] Re: JSON parser

2016-11-09 Thread pierre . curto
Hello, I am sorry I am not sure I understood what you wanted to achieve, however, if you need to extract a json object from your sql rows, here is some code that should do it: https://play.golang.org/p/92oFkprZfs HTH Pierre Le mercredi 9 novembre 2016 22:36:42 UTC+1, Sergio Hunter a écrit :

[go-nuts] Re: Multiple-reader single-writer map access - is this lockless workaround safe?

2016-09-12 Thread pierre . curto
You might be interested in this: https://golang.org/pkg/sync/atomic/#Value Le lundi 12 septembre 2016 17:04:39 UTC+2, sqweek E. a écrit : > > Ok so after getting away with using maps to share data between threads for > a lng time, I've finally seen the light and accepted that this is not >

[go-nuts] Re: Confused about defer

2016-08-26 Thread pierre . curto
To me this works as expected. In both your versions, the return statement in Recover() is not even reached since the call to f panics. You recover from the panic in your defer statement and assign the err variable your error value. Since in your first version, that variable is not returned,