Re: [go-nuts] is running interactive or not

2023-06-08 Thread Chris Burkert
Hi, there are cases when this does not work. I tend to use a flag like
-batch or -noninteractive to trigger the correct behavior from within
scripts. Less magic, more control.

Rich  schrieb am Do. 8. Juni 2023 um 20:19:

> Hi,
>
> I have a program I am writing that stops and asks the user for input, in
> this case it's a passphrase used to encrypt output.
>
>  I want the program to also be able to be used in a script, and if in a
> script use a predefined value as the passphrase. What I'd like to know is
> how to detect if running in a script or not.  I've tried something like
> this:
> runPid := os.Getpid()
> parPid := os.Getppid()
> val := runPid - parPid //normally I check if runPid is > parPid in my code.
> if val < 20 {
> fmt.Println("Not running in a script")
> }
> This works, but only if the script ran quickly. Wondering if there is a
> better way to do 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/c8ae1be5-5a6b-45af-9249-ccdb02283d97n%40googlegroups.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/CALWqRZoZqzYuDGtzZvHTPVFBSi8abjZz7cZK%3DYxmMisFf88dAA%40mail.gmail.com.


Re: [go-nuts] Learning Go on internal server

2023-02-16 Thread Chris Burkert
Go can be run on a regular Mac or PC. Maybe you don’t need a tools server
for this at all.

However, in a corporate environment caching dependencies may be a good
thing. With modules this is done by running your own Go proxy. Take a look
at
https://github.com/gomods/athens
 or
https://github.com/goproxy/goproxy.

Rich  schrieb am Do. 16. Feb. 2023 um 17:48:

> So, I've been writing go code for my company, and many have expressed an
> interest in learning Go. So what I want to do is create a learning
> environment for them on one of our 'tools' servers. The problem is that the
> tools server doesn't have good connectivity to the internet. So using go
> mod to download packages doesn't work. Is there a place I can download the
> package, put it on the server in a shared location so that go mod can pick
> up that it's already available?
>
> 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/64642177-5c5c-41d8-b508-66318e429276n%40googlegroups.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/CALWqRZp3%2BPdqoGD4wsVeHX8GEUyA1tGPa%2BB-ffiMSM5gJRQF5A%40mail.gmail.com.


Re: [go-nuts] extract VCS branch name used during build

2023-02-06 Thread Chris Burkert
You can use go:generate and go:embed to achieve this. In our CI/CD pipeline
we generate a json file with a lot of information like vcs, branch, tag,
date and time, hash and a lot more. Then we embed this json into the binary.

I became aware of this technique from
https://levelup.gitconnected.com/a-better-way-than-ldflags-to-add-a-build-version-to-your-go-binaries-2258ce419d2d?gi=c2bc81346d42
.

Hope this helps.

quin...@gmail.com  schrieb am Mo. 6. Feb. 2023 um 16:48:

>
> Hi,
>
> I would like to be able to extract the VCS branch name used during build.
> Currently I append "-X main.BranchName=${BRANCH}" to the build line which
> works, but I was hoping there might be a cunning way to extract this from
> runtime/debug?
>
> Thanks,
>
> -Steve
>
> --
> 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/6f0a10e1-f818-4b98-8384-3fe925ec69dcn%40googlegroups.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/CALWqRZqSMKbjEvOqF-AANNM4pFZ4cxEbmOKe46SRk7kU%3DdCwXQ%40mail.gmail.com.


Re: [go-nuts] Silly question about parentheses

2023-02-01 Thread Chris Burkert
Looking into the spec:

https://go.dev/ref/spec#Return_statements
ReturnStmt = "return" [ ExpressionList ] .
ExpressionList = Expression { "," Expression } .
... no () here

https://go.dev/ref/spec#Function_types
FunctionType   = "func" Signature .
Signature  = Parameters [ Result ] .
Result = *Parameters | Type* .
Parameters = *"("* [ ParameterList [ "," ] ] *")"* .
ParameterList  = ParameterDecl { "," ParameterDecl } .
ParameterDecl  = [ IdentifierList ] [ "..." ] Type .
... a *Type* does not need () but *Parameters* needs them.

But now I am puzzled. I can actually omit the variable name for the
arguments: https://play.golang.com/p/g4Sz8rh06QW.

This seems to be useless, but it is actually allowed, right?

Am Mi., 1. Feb. 2023 um 17:04 Uhr schrieb Raphael Clancy <
raphael.cla...@gmail.com>:

> This is really helpful! Thank you!
>
> At first I assumed that it was down to 'go fmt' letting you be fairly
> loose with your syntax and that you could omit parentheses where the
> meaning wouldn't be ambiguous.  But on closer examination, there must be
> something else going on because 'return a, b' works fine and 'return (a,
> b)' generates an error. But, both 'func(a string) string {}' and  'func(a
> string) (string){}' work fine.
>
> Maybe it's because 'return' isn't really a function call and has it's own
> syntax?
>
> On Wednesday, February 1, 2023 at 8:13:10 AM UTC-7
> axel.wa...@googlemail.com wrote:
>
>> Good point, didn't think of that
>>
>> On Wed, Feb 1, 2023, 15:30 p...@morth.org  wrote:
>>
>>> It would actually be ambiguous in the very place they're required.
>>>
>>> Consider this not completely unreasonable example:
>>> https://go.dev/play/p/OL0uOnPZXju
>>>
>>> Also, with generics it could be ambiguous in type parameters.
>>> To summarize, parentheses are needed around the return types because
>>> otherwise anywhere a list of types is used, it would be ambiguous.
>>>
>>> Regards,
>>> Per Johansson
>>>
>>> On Tuesday, January 31, 2023 at 8:38:46 PM UTC+1
>>> axel.wa...@googlemail.com wrote:
>>>
 I'm not sure there really is a "reason", per se. The language could
 just as well have been designed not to require parentheses around the
 return types (at least I see no parsing ambiguity with that, though there
 might be) or designed to require parentheses in the return statement. It
 probably just felt more intuitive and readable to the designers at the 
 time.

 FWIW I find it more interesting that `func() T` requires no
 parentheses, but `func() (S, T)` does.

 On Tue, Jan 31, 2023 at 5:55 PM Raphael Clancy 
 wrote:

> Hey all, I figured it was time to move to a "modern" language and I
> thought I'd give go a try. So far, I'm really enjoying it. I'm just 
> getting
> started and I had a question about parentheses. Though, I guess it's 
> really
> about how go parses lines of code and what counts as a delimiter.
>
> Anyway, in the get started section on error handling
> , why are parentheses
> required around string and error here:
>
> func Hello(name string) (string, error) {...
>
> but not around message and nil here:
>
> return message, nil
>
> I tried searching a bit but I couldn't come up with anything about
> such a basic topic.
>
> 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...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/b49dc8c2-26ea-46bc-b76a-708a2537207cn%40googlegroups.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.
>>>
>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/golang-nuts/56d23af2-b3dd-4c59-86d4-d14d56e73a93n%40googlegroups.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/68e7ec15-5b55-4d72-b12d-fa9bcab282edn%40googlegroups.com
> 

Re: [go-nuts] Underscore symbol

2022-11-05 Thread Chris Burkert
I am curious: from a compiler perspective, does that mean that by using _
simply less assembler instructions are created by not handling those
registers which relate to _?

Marcel Huijkman  schrieb am Sa. 5. Nov. 2022
um 09:18:

> When I explain it during my training I always say it is a trashcan
> variable, anything you put in is to be ignored on the spot.
>
> On Friday, November 4, 2022 at 10:10:20 PM UTC+1 Konstantin Khomoutov
> wrote:
>
>> On Fri, Nov 04, 2022 at 04:58:35AM -0700, Canuto wrote:
>>
>> > I'm just starting out with go ...
>> > I have searched for lights on this string but without success.
>> > What does this sign mean " _, err " , what the underscore symbol means
>> here?
>>
>> If you're starting with Go, please start with the Go Tour [1].
>> For instance, the use of this underscore sign is covered in [2].
>>
>> 1. https://go.dev/tour/
>> 2. https://go.dev/tour/moretypes/17
>>
>> --
> 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/6c745c54-b212-4bb6-8e40-00273e6ee2fan%40googlegroups.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/CALWqRZo-n%3D_16Ug8Rids3E502dFZcW5PPZueGKfDqA%2Bcg30X6A%40mail.gmail.com.


Re: [go-nuts] Re: about upstream?

2022-11-04 Thread Chris Burkert
I am also not a native speaker, but having a stream/river in mind, then
upstream seems to be where the water comes from and downstream where the
water is going to.
However, the OP mentioned that one micro service called the other which
tells me something about how the connection is established, but that does
not tell me how data is actually "flowing". Maybe in both directions :-)

Am Do., 3. Nov. 2022 um 22:18 Uhr schrieb TheDiveO :

> I've seen both usages depending on the writers' perspectives. For that
> reason I avoid the terms upstream and downstream in this context (services)
> like the plague and always ask people for clarification without using these
> two words. It's always fun to see this then sparking totally surprised
> reaction in others taking part in those conversations.
>
> The OP is perfectly right to ask this usinthe term "up/downstream" in the
> context of services, as I've seen and heard this often times for REST-based
> APIs, both from native as well as non-native speakers.
>
> On Wednesday, November 2, 2022 at 10:15:51 AM UTC+1 cuiw...@gmail.com
> wrote:
>
>> there are two micro service writen in go, let's call them A and B. A will
>> call B. In this scene we will call B is the upstream of A. or A is the
>> upstream of B? which one is correct way?
>
> --
> 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/80af4dc5-3c18-4f2a-a52b-026a93d0dac8n%40googlegroups.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/CALWqRZp40tBrq8T_EJT9hqUcb4tk%3DezbbZedU8H%2BLatLgHgiaw%40mail.gmail.com.


Re: [go-nuts] How do I set a pkg's version?

2022-11-02 Thread Chris Burkert
We used the traditional way for a long time. But with the embed package we
stopped this. This is a good blog post on the topic:
https://levelup.gitconnected.com/a-better-way-than-ldflags-to-add-a-build-version-to-your-go-binaries-2258ce419d2d
.

Am Mi., 2. Nov. 2022 um 09:54 Uhr schrieb Jakob Borg :

> On 2 Nov 2022, at 09:47, 'Mark' via golang-nuts <
> golang-nuts@googlegroups.com> wrote:
>
>
> Oh, except that debug.BuildInfo (unsurprisingly) is only available in
> debug not release builds. So I guess the answer is that there isn't any
> nice way to do it.
>
>
> What do you mean by debug vs release builds? I don't think Go makes that
> distinction.
>
> That said, the build info will not contain information about your tags and
> such. The traditional way to add that is to have a build script inject that
> using `-ldflags -X ...` to set the value of some variables in the program.
>
> //jb
>
> --
> 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/885E5726-E0CD-46B2-B572-900A2E87AE07%40kastelo.net
> 
> .
>

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


Re: [go-nuts] How do I set a pkg's version?

2022-11-01 Thread Chris Burkert
During CI/CD we create a json file with a few details (git tag, branch,
hash, date, time). Afterwards we compile Go Code which embeds this file
into the binary. During runtime flags like --version print the json.

Note that this is about the version of some binary - not the version of a
package. However, you could embed go.mod. But there may be better ways.

Hope this helps.

'Mark' via golang-nuts  schrieb am Di. 1.
Nov. 2022 um 16:34:

> I am creating a pkg.
> It has a `go.mod` file:
> ```
> module github.com/.../mypkg
>
> go 1.19
> ```
> And code files with functions in .go files all in the mypkg pkg.
>
> How do I specify which version the mypkg pkg is? I know about using `$
> git tag vX.Y.Z` and `$ git push origin vX.Y.Z`, but is there any way I can
> have this version in a file that can be accessed at build time or runtime?
>
> --
> 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/0a16b738-59e5-4885-90c8-cd168e308623n%40googlegroups.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/CALWqRZov4r%2BN2FiZug5mmwUwhYcvf08922UQU%3DMqfJKLFT8dBg%40mail.gmail.com.


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

2022-01-11 Thread Chris Burkert
Hi,
The standard sql package (https://pkg.go.dev/database/sql) comes with a
connection pool. I think it is the DB struct handling the pool.
The drivers which implement the details for a specific database product
usually come with plenty of documentation and examples. See
https://github.com/golang/go/wiki/SQLDrivers for a list of them.

Shishira Pradhan  schrieb am Sa. 8. Jan.
2022 um 15:29:

> Hello All,
>
> What is the appropriate and industry standard mechanism to send database
> connection across golang file to use in logic layer to get data from DB? It
> should be one time connection established and many time use the connection
> pool across all files.
>
> Thanks,
> Shishira
>
> --
> 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/bd5646b9-0615-4551-bafd-c0a2cd47ba22n%40googlegroups.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/CALWqRZrstDffeWn1tm5Uh8QDTPZpuEDeW1StdxaDy8WW7Gd%2BZA%40mail.gmail.com.


Re: [go-nuts] Where to copy vendor to the go docker builder?

2021-09-02 Thread Chris Burkert
Would it help to set up your own module proxy e.g. with
https://github.com/gomods/athens or
https://github.com/goproxy/goproxy?

K Prayogo  schrieb am Do. 2. Sept. 2021 um 03:54:

> I'm trying to make docker build faster for software that are built with
> golang
> tried to cache layer but it still slow when dependency changed since go
> mod download have to redownload whole dependency again and again.
>
> how to make use vendor directory on docker  build? (where to copy? so go
> build or go mod download/go mod vendor inside Dockerfile so it doesn't
> redownload agian and again)?
> I've tried to copy whole vendor, but it still redownloading
> tried to copy vendor to $GOPATH/pkg/mod, but it also still redownloading
> tried to copy vendor to $GOPATH/pkg/mod/cache/download, but it still
> redownloading
> where the correct way to put vendor directory?
>
>
> https://stackoverflow.com/questions/69020535/how-to-prevent-docker-build-from-redownloading-copied-golang-vendor
>
> --
> 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/a377ced9-16ce-4862-9478-70c2b10b4280n%40googlegroups.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/CALWqRZqfOLTxCg7_KVK4UevXoj6SP5-Vx4gc%2BK7F8itQRGYN7Q%40mail.gmail.com.


Re: [go-nuts] Re: vendoring related question/issue

2021-06-18 Thread Chris Burkert
I believe you should distinguish between the build and the run environment.
Your build environment is largely defined by the language and its
ecosystem, e.g. the vendor folder has a semantic for the Go tools. After
the build you deploy the resulting artifacts to your run environment. That
may be the go binary and files in a vendor folder. But the semantics of
that vendor folder is different.

Sachin Puranik  schrieb am Fr. 18. Juni 2021 um
05:24:

> Dear Gophers,
> I have some more thoughts about the vendoring issue I observed earlier.
>
> Preface :
> Basically while vendoring other than go files, nothing is copied in the
> vendor folder(except the embed package).
> It can be some Readme.MD, or some text file, or HTML templates.
>
>
> Issue Details:
> In the last email, thanks to Sean, she suggested that I use the
> https://pkg.go.dev/embed package.
> But I still see some issues.
> 1. As per package description, this will work compile-time, which means
> the files will be embedded in the binary and affect the size of the
> artifact.
> 2. Secondly I may want to use these files from the folder for different
> purposes, ex: - I need not embed them, but as a part of my own build step I
> collect all such dependencies from my module and move them to the common
> serve folder from where they are served to the web.
> 3. it could be literally any purpose.
>
> Ultimately I think it's the purview of developers on how to use those
> files being part of the package, hence they should not be discarded by
> applying smart compilation.
>
>
> Now there is another associated problem, Let's say I add that manually in
> my vendor folder, when I run  'go mod vendor', all these files are forcibly
> deleted while updating and I am back to square one.
>
> Can you help to resolve this?
>
> Regards,
> Sachin
>
>
>
>
> On Mon, May 10, 2021 at 10:29 AM Sachin Puranik 
> wrote:
>
>> Hi Sean,
>> Thanks for the response. Though I am not sure if the solution satisfies
>> my use case. I am doing some experimentation and will get back to you soon
>> with the findings.
>>
>> Thanks and Regards,
>> Sachin.
>>
>> On Sun, May 9, 2021 at 9:47 PM Sean Liao  wrote:
>>
>>> `go mod vendor` only includes what is needed to build your main module.
>>> 1.16 has https://pkg.go.dev/embed so you can embed static assets (such
>>> as template/html files) into your final binary
>>> (they will also be available in the vendor directory but I don't think
>>> this is your final goal)
>>>
>>> On Sunday, May 9, 2021 at 5:03:58 PM UTC+2 Sachin Puranik wrote:
>>>
 Hi Gophers,
 I noticed the following issue while vendoring the library.

 Preface :
 Basically, I created the module, for myself. This module contains
 rendering templates and HTML files, few test files alongside the code. they
 are all tightly coupled to my module.

 Issue:
 when I use this module in another project as a vendor module, I noticed
 that all the code files are copied well, but all my test files, HTML
 templates, and files are completely ignored. They are not available in the
 vendor folder.

 Kindly let me know if there is an option to achieve this, or am I doing
 something wrong?

 Thanks in advance,
 Best regards,
 Sachin.

 --
>>> 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/FAIN1fLonUc/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/66c0b083-fd53-4c96-8541-60a0fc23a581n%40googlegroups.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/CANE8YwiLfiNw3XeEnPb%3DX0tD6%2B6--THe34YaChjdOLV%2BGWa3KQ%40mail.gmail.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/CALWqRZrbWjDHnj4sC%3D5yekPHWy%2Bb28WwsvHhZEzBNbOZQfXFPw%40mail.gmail.com.


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

2021-04-08 Thread Chris Burkert
I have good experiences with trunk based development meaning that “master”
(we use “main”) is the main development line and you down-port to release
branches with cherry picking and tags. So as soon as you commit something
which is considered a major change (requiring a new version) then also
append /v2 to your module name in go.mod. Branch off a v1 before that
commit. But for me the only interesting version is the latest version and
such a v1 branch soon is a dead end with no activity. When you really have
to maintain older versions for a long time then you may consider a
different approach.

Marcin Romaszewicz  schrieb am Do. 8. Apr. 2021 um 01:43:

> 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
>
> My plan is to do development in a "v2" branch, which which will
> occasionally be rebased onto the "master" branch until that's no longer
> feasible, at which point I'll cherry pick or port important commits from
> master to v2.
>
> The v2 branch will start off with an annotated tag named "v2.0.0-alpha".
> and will begin to diverge from master, which is tagged with v1.x.x
>
> When I am ready to release the V2 branch, I plan to do the following.
>
> Top commit in master becomes a new branch, "v1", and any future V1 bug
> fixes go here.
>
> I will merge the V2 branch into master, and tag it as v2.0.0.
>
> Does this sounds like a reasonable plan? I would like, for the time being,
> for people to be able to work on V1 in master, and eventually master will
> become V2 while V1 is a branch.
>
> My alternative is to create a V1 branch today, and all future work in
> master is V2.
>
>
> -- Marcin
>
> --
> 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/CA%2Bv29LuBN-Z8V9xmkzNM1DmMowjtV4XsqOboRtY9pO%2BGYZ5ufw%40mail.gmail.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/CALWqRZoCHxOrx0WgfkCtRTHypHy9%3DbTjwNzo-UQO3jS-snAQHg%40mail.gmail.com.


[go-nuts] Thanks

2021-03-24 Thread Chris Burkert
Several messages during the last weeks irritated me and I guess I was not
the only one. Eventually we are all humans but often enough we don’t treat
ourselves like that. Let’s treat machines like machines and humans like
humans - not the other way round.

That’s why I want to say “Thank you Gophers”! Thanks to to Rob, Ken an
Robert for creating an awesome piece of software. Thanks to Russ and Ian
for continuing this work. And thanks to all the contributors no matter for
which company you work.

There will never be a 100% agreement on implementation details and there
will never be a perfect process for decision taking. I believe we are lucky
to have people who can take hard decisions when needed but can also say
“no”. I’d like to express my respect for their work. It’s too easy to blame
others in charge not being in their shoes.

Go is an awesome language with amazing tooling and the latest efforts will
not suddenly morph it into a mess. For some it will further improve, for
others it may become worse. But I believe that essentially Go will remain
awesome.

PS: please excuse me if I couldn’t find proper English terms. It’s already
hard in my mother tongue with Kode and Code and Quellcode and Quelltext :-)

-- 
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/CALWqRZqjPwkn%3DF7FKUrsvfsUxkJxJkQqjpgOv1joUrbTK%3DJ2FQ%40mail.gmail.com.


Re: [go-nuts] I am facing goroutine leak issue. I am using cloudfoundary goclient libary to do some operations - Create service/Lastoperation/Update/Delete service instance.

2020-05-30 Thread Chris Burkert
Most of us do not own a crystal ball but with some code reproducing the
issue  (http://sscce.org/) you may get helping answers.

 schrieb am Mi. 27. Mai 2020 um 19:07:

> goroutine profile: total 12
> 3 @ 0x1032760 0x10420bb 0x1309343 0x105fc71
> # 0x1309342   net/http.(*persistConn).writeLoop+0x122 
> /usr/local/go/src/net/http/transport.go:2210
>
> 2 @ 0x1032760 0x10420bb 0x1308069 0x105fc71
> # 0x1308068   net/http.(*persistConn).readLoop+0x998  
> /usr/local/go/src/net/http/transport.go:2032
>
>
>
> I am getting this.
>
>
> I am using cloudfoundary goclient libary to do some operations - Create 
> service/Lastoperation/Update/Delete service instance. Any inputs on 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/739c322a-74e1-40f4-9699-663728680ae9%40googlegroups.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/CALWqRZr_CQzzgFBEn4ajYc6e9LFYk_aKKf1Xn32mXfzzEBJ6Qw%40mail.gmail.com.


Re: [go-nuts] Re: flags package: shared flags and flag sets

2020-05-07 Thread Chris Burkert
Thank you very much.
This is exactly what I was looking for. A simple way without the need for
additional packages.
Highly appreciated!

Am Do., 7. Mai 2020 um 07:28 Uhr schrieb mural :

> https://play.golang.org/p/Sga78gMLn-9
>
> You can then use it like './mycli -d stream -rt'
>
> The '-d' option is a shared flag, and `-rt' is dedicated for the
> subcommand 'stream'.
>
>
> On Wednesday, May 6, 2020 at 8:08:25 PM UTC+8, Chris Burkert wrote:
>>
>> Dear all,
>>
>> I'd like to mix shared flags with flags specific to flag sets (cooltool
>>   ). However I struggle to parse the
>> shared flags only and pass the rest to the flagset for parsing. Here is
>> what I came up with:
>>
>> https://play.golang.org/p/Jazn3aSX9-d
>>
>> Do I have to pick a different flag library or can this be done with
>> package flag from the standard library?
>>
>> Thanks - Chris
>>
> --
> 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/1c81e2be-0920-4872-887e-19981a0543d1%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/1c81e2be-0920-4872-887e-19981a0543d1%40googlegroups.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/CALWqRZpaZ032J_G88WM2vFz9w2e9vO9K_PSYO7-QeGK_5t6CbQ%40mail.gmail.com.


[go-nuts] flags package: shared flags and flag sets

2020-05-06 Thread Chris Burkert
Dear all,

I'd like to mix shared flags with flags specific to flag sets (cooltool
  ). However I struggle to parse the
shared flags only and pass the rest to the flagset for parsing. Here is
what I came up with:

https://play.golang.org/p/Jazn3aSX9-d

Do I have to pick a different flag library or can this be done with package
flag from the standard library?

Thanks - Chris

-- 
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/CALWqRZoJJUCJkBmdZ6%2BU0ri3wjzo3se8%3DMYgfzB3uHSVhpf9_Q%40mail.gmail.com.


Re: [go-nuts] Re: marshal multiple json documents which may have different format versions into the latest struct version

2020-04-29 Thread Chris Burkert
That sounds like a good plan. I'm going to try that. Thank you Manlio!

Am Di., 28. Apr. 2020 um 15:11 Uhr schrieb Manlio Perillo <
manlio.peri...@gmail.com>:

> On Tuesday, April 28, 2020 at 10:52:56 AM UTC+2, Chris Burkert wrote:
>>
>> Dear all,
>>
>> my application users shall be able to provide multiple json documents
>> (files and urls) which I'd like to marshall into one structure.
>> Additionally these json documents may have different versions. I know how
>> to marshal a document into a version specific struct if I know the format
>> version before (for simplicity of this example I don't handle errors):
>> https://play.golang.org/p/ixVI5CzPqFP
>>
>> What I would like (in the example the village field was renamed to cities
>> ) is a struct of type ModelV2 with all four values merged in Cities.
>>
>> Is there a best practice for a backwards compatible behavior which:
>>
>>- identifies the json format version of each document
>>- skips that document if it is higher than the supported format
>>version in my application
>>- merges supported format versions into ONE struct
>>
>> Of course I have to implement the semantics on my own but how can I
>> approach the topic?
>>
>>
> You can first unmarshal a struct containing only the Version field.  As an
> example:
> https://play.golang.org/p/1oDzdWlTCfC
> <https://play.golang.org/p/6G9ooLneADX>
>
>
> Manlio
>
>> 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/274e489d-afdb-4ec9-a5b3-26440364c489%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/274e489d-afdb-4ec9-a5b3-26440364c489%40googlegroups.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/CALWqRZomuBCB_vV84WA%3DHnsRS%2BfzYOA%2B_2hLyGQAA1BU4VfXtg%40mail.gmail.com.


[go-nuts] marshal multiple json documents which may have different format versions into the latest struct version

2020-04-28 Thread Chris Burkert
Dear all,

my application users shall be able to provide multiple json documents
(files and urls) which I'd like to marshall into one structure.
Additionally these json documents may have different versions. I know how
to marshal a document into a version specific struct if I know the format
version before (for simplicity of this example I don't handle errors):
https://play.golang.org/p/ixVI5CzPqFP

What I would like (in the example the village field was renamed to cities )
is a struct of type ModelV2 with all four values merged in Cities.

Is there a best practice for a backwards compatible behavior which:

   - identifies the json format version of each document
   - skips that document if it is higher than the supported format version
   in my application
   - merges supported format versions into ONE struct

Of course I have to implement the semantics on my own but how can I
approach the topic?

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


Re: [go-nuts] the size of the files compiled in GO

2020-04-18 Thread Chris Burkert
https://golang.org/doc/faq#Why_is_my_trivial_program_such_a_large_binary

 schrieb am Sa. 18. Apr. 2020 um 19:25:

> Why does the simple Hello world program take 2 MB after compilation?
>
> --
> 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/4d572066-f044-4aa8-8661-5653381b6d81%40googlegroups.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/CALWqRZrM%2Bvm_P7QctRteOeKQncWoxNatVUVtPOcpL5fS115XuQ%40mail.gmail.com.


Re: [go-nuts] libgo is more fast that grouting.

2020-03-20 Thread Chris Burkert
Do people ask for a Tesla with a combustion engine? No because they value
what Tesla is doing and why they are doing it. And neither Tesla nor
Kubernetes or Docker are research projects. So please don’t whine about how
things are. Instead (as Ian said) participate in a positive manner and
contribute to make things better. The code of conduct is a good starting
point: https://golang.org/conduct

'Benjamin' via golang-nuts  schrieb am Fr.
20. März 2020 um 06:52:

> I think the team of go programming language should invite other people
> that out of google join some part of the project. And you all can have more
> free time.
>
> Sometimes Lazy is good habit. It’s 10+ years, go should not be a research
> project now. How Many 10 years do you have?  Like what is the binary
> package file of go? c/c++ have dll/so file, java has jar file, even php has
> a phar file.
>
> Guess what this project will happen when you all leave google? Only
> projects like PHP and Python and Java are real open source community driven
> project. They are all not belong to any company.
>
>
>
> > On Mar 19, 2020, at 00:00, Ian Lance Taylor  wrote:
> >
> > On Tue, Mar 17, 2020 at 11:12 PM 'Benjamin' via golang-nuts
> >  wrote:
> >>
> >> Benchmark shows that lingo is faster than goroutine.
> >>
> >> Many china internet companies use similar c++ libraries to support
> trillions of concurrency.
> >> Like Tencent use a smiler project libco:
> >> https://github.com/Tencent/libco
> >>
> >> I think the go team should learn some idea from these projects.
> >> NOT invent new thing is not necessary, its waste of time. Not all
> developers have 10+ years time to wait a new programming language become
> maturity .
> >
> > Go is an open source project.  I encourage you, and anyone who is
> > interested, to investigate these libraries to understand why they are
> > faster, and what Go can do to speed up.  The more people work on Go,
> > the less time everyone will have to wait for better performance.
> > Thanks.
> >
> > Ian
>
> --
> 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/70EE3DB8-EE16-4A70-B72E-D01E48EF4C82%40icloud.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/CALWqRZp-27ukWRVEzQO5qDWK0b%3DQOiM3y-QWTi-Shyv0wpS%3Dfg%40mail.gmail.com.


Re: [go-nuts] Re: McAfee and the module cache on WSL: rename : permission denied

2020-03-13 Thread Chris Burkert
Hello Alex,
this describes exactly my issue. I am going to test if the workarounds in
tip solve my case and also ask my companies IT department to
exclude 
%LOCALAPPDATA%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc
from the scanning.

Hello Jonathan,
thanks for the links. I learned something new.

many thanks to both of you

Am Fr., 13. März 2020 um 19:47 Uhr schrieb brainman :

> On Friday, 13 March 2020 08:58:24 UTC+11, Chris Burkert wrote:
>>
>> Dear all,
>>
>> besides other environments I have a company laptop running Windows 10
>> Enterprise with WSL and Ubuntu. In Ubuntu I installed Go 1.14 and wanted to
>> play around with Gio for fun. However it seems that McAfee doesn't want me
>> to.
>>
>>
> https://github.com/golang/go/issues/36568
>
> Alex
>
> --
> 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/c4b9fcfb-def6-491f-ac32-65eff12d172a%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/c4b9fcfb-def6-491f-ac32-65eff12d172a%40googlegroups.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/CALWqRZr6cuP%2BCiDG684kLG1pEShHD4%3D%3D1BcWvUjQam%3DqGj6%2BjA%40mail.gmail.com.


[go-nuts] McAfee and the module cache on WSL: rename : permission denied

2020-03-12 Thread Chris Burkert
Dear all,

besides other environments I have a company laptop running Windows 10
Enterprise with WSL and Ubuntu. In Ubuntu I installed Go 1.14 and wanted to
play around with Gio for fun. However it seems that McAfee doesn't want me
to.

In short this is what I do and (mostly) get:

$ cd ~
$ mkdir test
$ cd test
$ go mod init test;
$ wget
https://git.sr.ht/~eliasnaur/gio/blob/master/example/kitchen/kitchen.go
$ go run kitchen.go
go: finding module for package gioui.org/unit
go: finding module for package gioui.org/layout
go: finding module for package gioui.org/app/headless
go: finding module for package gioui.org/font/gofont
go: finding module for package golang.org/x/exp/shiny/materialdesign/icons
go: finding module for package gioui.org/app
go: finding module for package gioui.org/io/system
go: finding module for package gioui.org/text
go: finding module for package gioui.org/widget
go: finding module for package gioui.org/widget/material
go: downloading gioui.org v0.0.0-20200312174220-af68e17dd324
go: downloading golang.org/x/exp v0.0.0-20200228211341-fcea875c7e85
kitchen.go:20:2: rename
/home/d055539/go/pkg/mod/gioui@v0.0.0-20200312174220-af68e17dd324.tmp-663496537
/home/d055539/go/pkg/mod/gioui.org@v0.0.0-20200312174220-af68e17dd324:
permission denied
kitchen.go:21:2: rename
/home/d055539/go/pkg/mod/gioui@v0.0.0-20200312174220-af68e17dd324.tmp-663496537
/home/d055539/go/pkg/mod/gioui.org@v0.0.0-20200312174220-af68e17dd324:
permission denied
kitchen.go:31:2: rename
/home/d055539/go/pkg/mod/gioui@v0.0.0-20200312174220-af68e17dd324.tmp-663496537
/home/d055539/go/pkg/mod/gioui.org@v0.0.0-20200312174220-af68e17dd324:
permission denied
kitchen.go:22:2: rename
/home/d055539/go/pkg/mod/gioui@v0.0.0-20200312174220-af68e17dd324.tmp-663496537
/home/d055539/go/pkg/mod/gioui.org@v0.0.0-20200312174220-af68e17dd324:
permission denied
kitchen.go:23:2: rename
/home/d055539/go/pkg/mod/gioui@v0.0.0-20200312174220-af68e17dd324.tmp-663496537
/home/d055539/go/pkg/mod/gioui.org@v0.0.0-20200312174220-af68e17dd324:
permission denied
kitchen.go:24:2: rename
/home/d055539/go/pkg/mod/gioui@v0.0.0-20200312174220-af68e17dd324.tmp-663496537
/home/d055539/go/pkg/mod/gioui.org@v0.0.0-20200312174220-af68e17dd324:
permission denied
kitchen.go:25:2: rename
/home/d055539/go/pkg/mod/gioui@v0.0.0-20200312174220-af68e17dd324.tmp-663496537
/home/d055539/go/pkg/mod/gioui.org@v0.0.0-20200312174220-af68e17dd324:
permission denied
kitchen.go:26:2: rename
/home/d055539/go/pkg/mod/gioui@v0.0.0-20200312174220-af68e17dd324.tmp-663496537
/home/d055539/go/pkg/mod/gioui.org@v0.0.0-20200312174220-af68e17dd324:
permission denied
kitchen.go:27:2: rename
/home/d055539/go/pkg/mod/gioui@v0.0.0-20200312174220-af68e17dd324.tmp-663496537
/home/d055539/go/pkg/mod/gioui.org@v0.0.0-20200312174220-af68e17dd324:
permission denied
kitchen.go:29:2: rename /home/d055539/go/pkg/mod/
golang.org/x/e...@v0.0.0-20200228211341-fcea875c7e85.tmp-991628004
/home/d055539/go/pkg/mod/golang.org/x/exp@v0.0.0-20200228211341-fcea875c7e85:
permission denied

I wrote that this is the output I mostly get because in some cases I get a
slightly different error. For example after repeating the go run often
enough the golang.org/x/exp was cached fine.

I was not able to reproduce this on any of the other environments (various
pure Linux VMs).

During the go run McAfee is busy and I assume it causes the errors.
Unfortunately I cannot switch off McAfee to prove that.

Do you see similar issues with this combination of WSL and the McAfee
scanner? Or am I doing something stupid here and just don't see my fault?

thanks - Chris

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


Re: [go-nuts] Preserving extra properties using JSON unmarshal / marshal?

2020-02-21 Thread Chris Burkert
Take a Look at
https://blog.golang.org/json-and-go:

The json package uses map[string]interface{} and []interface{}values to
store arbitrary JSON objects and arrays; it will happily unmarshal any
valid JSON blob into a plain interface{} value. The default concrete Go
types are:

   - bool for JSON booleans,


   - float64 for JSON numbers,


   - string for JSON strings, and


   - nil for JSON null.


Does this help?

'Eric Johnson' via golang-nuts  schrieb am
Fr. 21. Feb. 2020 um 19:00:

> If I've got a structure like this:
>
> type jsonData struct {
> FirstName string `json:"first_name"`
> LastName  string `json:"last_name"`
> }
>
> I can marshal / unmarshal JSON as:
> {
>   "first_name": "first",
>   "last_name": "last"
> }
>
> What if my input JSON is this:
> {
>   "first_name": "first",
>   "last_name": "last",
>   "favorite_color": "orange",
>   "age": 92
> }
>
> Is there an existing library to have a structure that's something like
> this:
>
> type jsonData struct {
> FirstName string `json:"first_name"`
> LastName  string `json:"last_name"`
> Extrasmap[string]interface{} `json:",extras"`
> }
>
> Such that a JSON unmarshal and marshal will preserve the data of the
> original JSON?
>
> I think I can probably make something work with the standard library,
> except that it will require extra marshaling / unmarshaling steps that will
> be annoying to reproduce for each structure that needs to capture extra
> data. So I'm hoping there's a better solution?
>
> Eric
>
>
> --
> 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/630827e2-8277-4231-9ab1-31881198a386%40googlegroups.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/CALWqRZqikwfQ9RJNUWtt3YKSkFcfFYFn9LadOzFEq7Gsfga7cA%40mail.gmail.com.


Re: [go-nuts] Sybase SQLAnywhere driver for Unix systems

2020-01-16 Thread Chris Burkert
Hello, we are working on a pure Go implementation of the TDS protocol for
https://github.com/SAP/go-ase (which is currently just a cgo driver). I am
not sure if TDS is also understood by SQLAnywhere but if so, then this may
help. I will see if I find more in the company and let you know.

reda laanait  schrieb am Di. 7. Jan. 2020 um 14:23:

>
> Hello,
>
> Is there a Golang driver for Sybase SQLAnywhere DB that works in a Unix
> system? I only find this , which
> works only on windows.
>
> Otherwise, Is there any workaround to fix that e.g implementing a wrapper
> of another language driver?
>
> Thanks
>
> --
> LAANAIT Ahmed Reda
> --
> Computer Engineer at
> TamTam international
>
> --
> 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/CAJg1kZP_68-XsdSXHzkSm2mOPuP%2BptLpihCsmcOtLJ734XyZcw%40mail.gmail.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/CALWqRZoqx2ioV--5VMnZwkKebA3CPXc6X7%3Dvb1m-x9cM80sYCQ%40mail.gmail.com.


Re: [go-nuts] Mocked method not working in golang while running the test cases

2020-01-11 Thread Chris Burkert
You could inject your dependencies. There is a funny talk by Liron Levin
[1] which helped me a lot.

1: https://youtu.be/_B_vCEiO4mA

prakash sharma  schrieb am Sa. 11. Jan. 2020
um 16:24:

> Need help:
>
> https://stackoverflow.com/questions/59693971/mocked-method-not-working-in-golang-while-running-the-test-cases
>
> I am trying to mock an struct method in test cases but it is not working.
> I want to mock *Validate* method here:
>
> package main
>
> import (
> "fmt"
> )
>
> type DemoInterface interface {
> Inc(int) (int, error)
> Validate(int) error
> }
> type DemoStruct struct{}
>
> func (l DemoStruct) Inc(num int) (int, error) {
> err := l.Validate(num)
> if err != nil {
> return 0, err
> }
> num = num + 100
> return num, nil
>
> }
> func (l DemoStruct) Validate(num int) error {// SOME DB LOGIC IS HERE WHICH I 
> CAN NOT POST at Stackoverflow
> if num > 100 {
> return fmt.Errorf("INVALID NUM %v", num)
> }
> return nil
> }
>
> func main() {
> s, err := DemoStruct{}.Inc(10)
> if err != nil {
> fmt.Println(err)
> }
> fmt.Println(s)
>
> }
>
>
>
> My test cases:
>
> package main
>
> import (
> "fmt"
> "testing"
> )
>
> const (
> SUCCESS = "SUCCESS"
> ERROR   = "ERROR"
> )
>
> type MockDemoStruct struct {
> DemoStruct
> functionality string
> }
>
> func (m MockDemoStruct) Validate(num int) error {
> switch m.functionality {
> case SUCCESS:
> return nil
> case ERROR:
> fmt.Errorf("MOCK ERROR %v", num)
>
> }
> return fmt.Errorf("MOCK ERROR %v", num)
> }
>
> func TestPath(t *testing.T) {
>
> t.Run("ERROR", func(t *testing.T) {
> ls := MockDemoStruct{DemoStruct{}, SUCCESS}
> res, err := ls.Inc(110)
> expected := fmt.Errorf("MOCK ERROR %v", 10)
> if err != expected {
> t.Errorf("NOT MATCH  %v  %v", err, expected)
> //-NOT MATCH  INVALID NUM 110  MOCK ERROR 10 
> ERROR-
>
> }
> fmt.Println(res)
> })
> }
>
>
>
> --
> 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/a90f9eee-cebb-4d2d-b1cf-76b16faee296%40googlegroups.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/CALWqRZqfjL0-5ZaSJOywLFaJoebmvh7Mfb%2BsnpGpEE1M6Aj%3D7g%40mail.gmail.com.


Re: [go-nuts] How do I initialize extemplate (a template engine in golang) so that I can use with Echo minimalist framework

2020-01-08 Thread Chris Burkert
xt := {} leaves the templates field nil.

Ehioje Henry Erabor  schrieb am Mi. 8. Jan. 2020 um
15:59:

> I am having issues using extemplate library in my echo framework project.
> Library :https://github.com/dannyvankooten/extemplate
>
> My Code is below:
>
> Enter code here...package main
>
> import (
> "fmt"
> "io"
> "net/http"
>
> "github.com/dannyvankooten/extemplate"
> "github.com/labstack/echo/v4"
> )
>
> // Template ...
> type Template struct {
> templates *extemplate.Extemplate
> }
>
> // Render ...
> func (t *Template) Render(w io.Writer, name string, data interface{}, c
> echo.Context) error {
> err := t.templates.ExecuteTemplate(w, name, data)
> if err != nil {
> fmt.Println("error", err)
> return err
> }
>
> return nil
> }
>
> // Page ...
> type Page struct {
> Name string
> Content string
> }
>
> // Hello ...
> func Hello(c echo.Context) error {
> return c.Render(http.StatusOK, "hello.html", "Guys")
> }
>
> // About ...
> func About(c echo.Context) error {
>
> data := Page{
> Name: "About", Content: `Lorem ipsum dolor sit amet, consectetur
> adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
> aliqua.
> Nisi scelerisque eu ultrices vitae auctor eu augue ut lectus. Quam
> pellentesque nec nam aliquam sem et tortor consequat.
> Pharetra vel turpis nunc eget lorem dolor. Vitae turpis massa sed
> elementum tempus egestas. Turpis egestas pretium aenean pharetra magna ac
> placerat.
> Neque ornare aenean euismod elementum nisi quis eleifend quam. In
> fermentum et sollicitudin ac orci. Ut porttitor leo a diam sollicitudin
> tempor id eu nisl.
> Sed viverra tellus in hac habitasse platea dictumst vestibulum rhoncus.
> Lorem ipsum dolor sit amet. A diam sollicitudin tempor id eu. Sit amet
> facilisis magna etiam.
> Praesent tristique magna sit amet purus gravida.`,
> }
> return c.Render(http.StatusOK, "about.html", data)
> }
>
> func main() {
>
> xt := {}
> err := xt.templates.ParseDir("templates/", []string{".html"})
> if err != nil {
> fmt.Println("ErrorExt: ", err)
> }
>
> e := echo.New()
> e.Renderer = xt
> e.GET("/hello", Hello)
> e.GET("/about", About)
>
> e.Logger.Fatal(e.Start(":4000"))
>
> }
>
>
> My folder structure where the template resides is below:
>
> --main--
> --templates--
>--about.html--
>--home.html--
> --go.mod--
> --go.sum--
>
> I am using go modules for the project.
> Why do I keep on getting these errors below:
>
> panic: runtime error: invalid memory address or nil pointer dereference
>> [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x776c85]
>> goroutine 1 [running]:
>> github.com/dannyvankooten/extemplate.(*Extemplate).ParseDir(0x0,
>> 0x8cb153, 0xa, 0xcebf20, 0x1, 0x1, 0x32, 0x963ae0)
>> /home/henry/work/pkg/mod/
>> github.com/dannyvankooten/extemplate@v0.0.0-20180818082729-efbdf6eacd7e/template.go:110
>> +0x125
>> main.main()
>> /home/henry/goproject/extemplate/main.go:56 +0xa7
>> exit status 2
>
>
>
>
>
> --
> 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/0b664dbf-4ca4-41e5-aa55-b514101b81c6%40googlegroups.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/CALWqRZq9-JxPakU7L3Brds7F4J0E6NeJPc-TxzJ2b0m9KQkgOg%40mail.gmail.com.


Re: [go-nuts] Simple worker pool in golnag

2019-12-28 Thread Chris Burkert
I needed a way to let the database complete a few tables (max 25) at a time
without the need for the database to handle other tables in between. A
worker pool which reads one table after the other does that perfectly. That
also means that if all workers wait for the database then my whole program
waits - which is intented. I didn't test it but I guess that one goroutine
per table would burden the database to handle all tables at once. I asume
that a goroutine which triggered the database and waits for it to complete
is put aside by the runtime letting other goroutines also trigger the
database. And I think then I will have the same out of memory (on the
database side, not on the Go side). However I try to test the "one
goroutine per table" approach ... maybe it improves my code and I learn
something new.

Anyway, all I wanted to say was that there are situations where one
approach fits more while it may be opposite in another situation. And I
don't like the term "anti-pattern" as it lets you put ideas aside which may
be worth thinking about.

Am Sa., 28. Dez. 2019 um 14:01 Uhr schrieb Agniva De Sarker <
agniva.quicksil...@gmail.com>:

> > (the task was to limit the whole thing to about 10% of cores)
>
> I still don't think you needed a worker pool here. Like OP mentioned
> above, you could just limit the number of goroutines executed to 10% of
> total cores.
>
>
> On Saturday, 28 December 2019 18:02:08 UTC+5:30, Chris Burkert wrote:
>>
>> There are Pros and Cons for everything in life. Some time ago I wrote a
>> database tool which does something per table where the runtime largely
>> depends on the table size. I started with one goroutine per table because
>> it was easy. But that put a high load on the database (the task was to
>> limit the whole thing to about 10% of cores) with out of memory situations.
>> So I switched to a worker pool which solved that. However now the overall
>> runtime was unpredictable. When the large tables were handled at the end
>> their runtime defined the overall runtime. So I to feed the pool with large
>> tables first. This again lead to out of memory situations so I reordered
>> the tables such that large tables are mixed with smaller tables.
>>
>> Brian Candler  schrieb am Sa. 28. Dez. 2019 um 11:09:
>>
>>> On Friday, 27 December 2019 16:30:48 UTC, Bruno Albuquerque wrote:
>>>>
>>>> This might be useful too you, in any case:
>>>>
>>>> https://git.bug-br.org.br/bga/workerpool
>>>>
>>>>
>>> I think the point from Bryan Mills' video is, "worker pool" is something
>>> of an anti-pattern in go.  goroutines are so cheap that you might as well
>>> start a goroutine for each piece of work you have to do, and let it
>>> terminate when that piece of work is done.
>>>
>>> Apart from the startup cost, the other reason for having a "worker pool"
>>> is to limit the number of concurrent tasks being executed, and there are
>>> better ways of doing that in go (also shown in the video).
>>>
>>> --
>>> 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 golan...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/golang-nuts/f840beee-748f-42b6-809f-4c7505208aee%40googlegroups.com
>>> <https://groups.google.com/d/msgid/golang-nuts/f840beee-748f-42b6-809f-4c7505208aee%40googlegroups.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/ecddafbc-eb73-45e1-8a5a-f738e88c6821%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/ecddafbc-eb73-45e1-8a5a-f738e88c6821%40googlegroups.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/CALWqRZq0%2B7-d9iyOZ0bz93EZisS6UVwfsDiJukhJuYRjP6xuOw%40mail.gmail.com.


Re: [go-nuts] Simple worker pool in golnag

2019-12-28 Thread Chris Burkert
There are Pros and Cons for everything in life. Some time ago I wrote a
database tool which does something per table where the runtime largely
depends on the table size. I started with one goroutine per table because
it was easy. But that put a high load on the database (the task was to
limit the whole thing to about 10% of cores) with out of memory situations.
So I switched to a worker pool which solved that. However now the overall
runtime was unpredictable. When the large tables were handled at the end
their runtime defined the overall runtime. So I to feed the pool with large
tables first. This again lead to out of memory situations so I reordered
the tables such that large tables are mixed with smaller tables.

Brian Candler  schrieb am Sa. 28. Dez. 2019 um 11:09:

> On Friday, 27 December 2019 16:30:48 UTC, Bruno Albuquerque wrote:
>>
>> This might be useful too you, in any case:
>>
>> https://git.bug-br.org.br/bga/workerpool
>>
>>
> I think the point from Bryan Mills' video is, "worker pool" is something
> of an anti-pattern in go.  goroutines are so cheap that you might as well
> start a goroutine for each piece of work you have to do, and let it
> terminate when that piece of work is done.
>
> Apart from the startup cost, the other reason for having a "worker pool"
> is to limit the number of concurrent tasks being executed, and there are
> better ways of doing that in go (also shown in the video).
>
> --
> 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/f840beee-748f-42b6-809f-4c7505208aee%40googlegroups.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/CALWqRZp2fczzwK%2BTo-WGXB8ZkWxu1Jgbin%3DKuoJbnScMebrSNw%40mail.gmail.com.


Re: [go-nuts] How to execute a command using root?

2019-08-31 Thread Chris Burkert
Dear Kevin,
is there some code available to dig into that? I plan to do something
similar that a regular user process starts up a kind of a root broker which
starts several other processes as different users. Especially for the
communication part I don’t have a good and secure idea so far.
thanks - Chris

Kevin Chadwick  schrieb am Fr. 30. Aug. 2019 um 13:13:

> On 8/30/19 7:49 AM, Benjamin wrote:
> > Do anyone have any suggestions on this? Thanks
>
> Sudo is an option. I prefer to have a master root process that spawns
> workers
> processes that drop privileges via setegid...seteuid... syscalls to
> dedicated
> users for various tasks. Takes concurrency to the next level and organises
> your
> code, but it is more work. Also allows flexibility on chrooting that
> requires
> root (though I find OpenBSDs unveil more useful mostly but occasionally
> both).
>
> If you don't want a process to be taken down by a process group fatal then
> fork
> it separately via a startup shell script.
>
> --
> 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/8908b67e-d5d6-698b-bd54-f2c95fc2566f%40gmail.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/CALWqRZr%3Da0APK%2Bv6CQ9S9ptXrT2ok0OssNH4Kj3kmwtbmED%2BrA%40mail.gmail.com.


[go-nuts] Re: the Dominance of English in Programming Languages

2019-05-04 Thread Chris Burkert
Some background why I was asking this: I have a history with
Squeak/Smalltalk and how Alan Kay worked with children. At work I also
teach 14/15 year old pupils during their 2 weeks internship and that is
simply too short to show them something about programming especially when
this is just one topic out of many. We usually convert numbers between
decimal, octal, binary and hexadecimal on the whiteboard. And because they
just knew 0-9 so far it becomes a sudden insight to some of them. These few
kids usually want to learn more (convert numbers programmatically) but
because they are intrinsically motivated the English language is not a
hurdle for them. That’s why I was wondering about the article.

Thanks for all your comments. Reading the different perspectives about the
topic fascinates me a lot.

Chris Burkert  schrieb am Mo. 29. Apr. 2019 um
07:35:

> I recently read an article (German) about the dominance of English in
> programming languages [1]. It is about the fact that keywords in a language
> typically are English words. Thus it would be hard for non English speakers
> to learn programming - argue the authors.
>
> I wonder if there is really demand for that but of course it is weird to
> ask that on an English list.
>
> I also wonder if it would be possible on a tooling level to support
> keywords in other languages e.g. via build tags: // +language german
>
> Besides keywords we have a lot of names for functions, methods, structs,
> interfaces and so on. So there is definitely more to it.
>
> While such a feature may be beneficial for new programmers, to me it comes
> with many downsides like: readability, ambiguous naming / clashes, global
> teams ...
>
> I also believe the authors totally miss the point that learning Go is
> about to learn a language as it is because it is the language of the
> compiler.
>
> However I find the topic interesting and want to hear about your opinions.
>
> thanks - Chris
>
> 1:
>
> https://www.derstandard.de/story/2000101285309/programmieren-ist-fuer-jeden-aber-nur-wenn-man-englisch-spricht
>

-- 
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] the Dominance of English in Programming Languages

2019-04-28 Thread Chris Burkert
I recently read an article (German) about the dominance of English in
programming languages [1]. It is about the fact that keywords in a language
typically are English words. Thus it would be hard for non English speakers
to learn programming - argue the authors.

I wonder if there is really demand for that but of course it is weird to
ask that on an English list.

I also wonder if it would be possible on a tooling level to support
keywords in other languages e.g. via build tags: // +language german

Besides keywords we have a lot of names for functions, methods, structs,
interfaces and so on. So there is definitely more to it.

While such a feature may be beneficial for new programmers, to me it comes
with many downsides like: readability, ambiguous naming / clashes, global
teams ...

I also believe the authors totally miss the point that learning Go is about
to learn a language as it is because it is the language of the compiler.

However I find the topic interesting and want to hear about your opinions.

thanks - Chris

1:
https://www.derstandard.de/story/2000101285309/programmieren-ist-fuer-jeden-aber-nur-wenn-man-englisch-spricht

-- 
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] Different Languages of a Program Project

2019-03-04 Thread Chris Burkert
John, the Web Browser communicates with the Web Server using the http
protocol. So http is the definition how they interact with each other. It’s
not a language but a protocol.

The Web Browser can display (or render) stuff which has been transferred
via http. This could be some HTML with the help of JavaScript. HTML is a
markup language and you cannot program with it. It is comprises the parts
your web page is made of e.g. a table. JavaScript on the other hand is a
language one can program with (e.g. the animations you mention). A third
thing is CSS used to position or colorize HTML elements like a table.

The Web Server of course should be the one from Go :) But there are many
around. The simplest way is to serve a directory which contains HTML, CSS
and JavaScript files. It becomes interesting when your Web Server creates
dynamic HTML using some logic. This can become complicated when you have a
database or services which your Go code connects to. Then things like sql,
rest, grpc or soap come into the game. But that might be too much for the
moment.

Hope this helps.

John  schrieb am Mo. 4. März 2019 um 02:07:

> I have come to a realization about programming and the different roles of
> each language in a project. Here below are what I thought, and hope that I
> may receive confirmation from my fellow programmers. Thank you.
>
> Golang: Main Project Management
> HTML: Website Formatting
> Javascript: Creating Animations etc.
> HTTP: Web Page Management
>
> --
> 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 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] Good metaphor for differentiating Go from other languages?

2019-02-23 Thread Chris Burkert
For me Go is the small but complete toolbox you need to build anything. Tim
Allens Home Improvement and Binford comes to my mind :-)

Randall O'Reilly  schrieb am Sa. 23. Feb. 2019 um
05:40:

> On the topic of “selling” the advantages of Go vs. other languages such as
> Python and C++, has anyone used the metaphor of other products that
> strongly emphasize clean, elegant design, such as Apple hardware (I
> wouldn’t make this case about their software, given the nature of
> objective-C and Swift), the Tesla cars, and other such “icons” of modern
> design?  It just occurred to me that this might be a powerful way to relate
> in one simple way what it is that people find so appealing about Go.  By
> comparison, every other language is clunky and ugly, etc..
>
> e.g., I could imagine someone writing something like this:
>
> https://www.smithsonianmag.com/arts-culture/how-steve-jobs-love-of-simplicity-fueled-a-design-revolution-23868877/
>
> about Go vs. other programming languages, and in the process, really
> communicating the essence of what is so great about the language in a way
> that people can tangibly understand.  I see so many discussions and
> misunderstandings about Go being “kinda like C” and that is just so far
> from the mark.
>
> Rob Pike’s talk:
> https://talks.golang.org/2015/simplicity-is-complicated.slide#1 makes all
> these points of course, very compellingly, but I wonder if adding the
> simple point “Go is the Bauhaus of programming languages" as a kind of
> tag-line.  The practical problem is that many people probably don’t know
> Bauhaus anymore, and saying “Go is the Apple of programming languages” has
> all kinds of issues...  Tesla?  Steve Jobs instead of Apple?
>
> - Randy
>
> --
> 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 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] Are defered function calls executed?

2019-01-03 Thread Chris Burkert
In case of a non-nil error Close will not be executed and that is exactly
what you want. The power of defer becomes obvious with more code after the
defer which does not have to deal with any cleanup of previous steps
because of the defer.

Am Fr., 4. Jan. 2019 um 07:09 Uhr schrieb 伊藤和也 :

> In the first example, "ok" was not printed.
>
> func main() {
>if(true) {
>   return
>}
>defer fmt.Println("ok")
> }
>
> So in the second example, is the Close function executed after an error 
> occurs and returned.
>
> func main() {
>src, err := os.Open("text.txt")
>if err != nil {
>   return
>}
>defer src.Close()
> }
>
> --
> 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 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] What are the reasonable reasons to use pointers?

2019-01-01 Thread Chris Burkert
Pointers are useful to pass around shared state. Values are usually copied
so changes on one copy are not visible on the other. Pointers on the other
hand are an address to some value (and the address is also copied by
passing it around) but the value these addresses point to is exactly one
same value so changes done via one pointer are visible via the other one.

I see it like this: „here’s your meal” is a value, “your meal is in the
fridge” is a pointer to a value and “your meal is in the cookbook” is a
pointer to a pointer to a value :-)

伊藤和也  schrieb am Di. 1. Jan. 2019 um 12:34:

> What are the reasonable reasons to use pointers? Are pointers neseccary?
>
> --
> 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 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] Channels: selecting the last element

2018-12-18 Thread Chris Burkert
Thanks Robert,
Daves article is mind opening. I created 4 variants of my program to
compare the effects and to give others the chance to study it:

   1. https://play.golang.org/p/WE_CbRlfTFf
   2. https://play.golang.org/p/FnuzyEVHS-I
   3. https://play.golang.org/p/S9ssTxlZK6X
   4. https://play.golang.org/p/XHLGfjYUP17

For the moment I will go for the second variant with buffered and disabled
channels.
Thanks to all!

Am Di., 18. Dez. 2018 um 21:03 Uhr schrieb robert engels <
reng...@ix.netcom.com>:

> This may be a helpful read:
>
> https://dave.cheney.net/2013/04/30/curious-channels
>
> On Dec 18, 2018, at 2:02 PM, robert engels  wrote:
>
> To clarify the semantics aspects:
>
> If A cannot proceed until B performs it’s work, because there is a
> dependency, then using a unbuffered channel simplifies a lot - you will
> always be at most “one event ahead” without any extra synchronization (wait
> groups, etc.)
>
> On Dec 18, 2018, at 2:01 PM, robert engels  wrote:
>
> Whether to use buffered or unbuffered comes down to two things:
>
> 1) the semantics of the communication. because using unbuffered channels
> simplifies a lot - knowing the send will not complete until the read
> completes - it provides a synchronization mechanism between events/messages
> and routines.
>
> 2) performance… imagine the following pseudo code:
>
> routine A sends messages to routine B
> routine B's processing of messages is variable - sometimes very fast,
> sometimes very slow…
> --- for example, let B be a logger, that every once in a while needs
> to write to disk (the much slower operation)
>
> so if A is a low latency event processor - getting stuck trying to send to
> B would not be ideal - but since this only happens ‘rarely’ by using a
> buffered channel (with the size = number of events expected in a B “slow”
> time), you avoid “blocking” A
>
> for example, A is sending financial orders to an exchange - you would not
> want to every slow A down just because the logger was slow
>
> For the performance aspect, you are essentially increasing the
> parallelism, since any “block/wait” degrades this
>
> Hope that helps.
>
>
>
> On Dec 18, 2018, at 1:49 PM, Chris Burkert 
> wrote:
>
> Robert,
> it seems to me that you have a clear understanding about unbuffered vs.
> buffered channels. I feel unbuffered channels are safer to use especially
> in an acyclic directed graph of flowing values. Buffered channels seem to
> reduce blocking but I feel they come with the cost of such side effects
> like my initial problem of forgotten results in their channels. I would
> love to hear/read/see more on the unbuffered vs. buffered tradeoff to get
> rid of this gut feeling I am currently based on :-). Any good article you
> can point me to?
> Thanks
>
> Robert Engels  schrieb am Di. 18. Dez. 2018 um
> 17:03:
>
>> That code is incorrect as well when using buffered channels.
>>
>> On Dec 18, 2018, at 10:00 AM, Skip Tavakkolian <
>> skip.tavakkol...@gmail.com> wrote:
>>
>> why not just  drop the select? i think the following is guaranteed
>> because putting things on rc has to succeed before putting true into dc:
>>
>> package main
>>
>> import (
>> "fmt"
>> )
>>
>> func do(i int, rc chan<- int, dc chan<- bool) {
>> rc <- i
>> dc <- true
>> }
>>
>> func main() {
>> worker := 10
>> rc := make(chan int, worker)
>> done := 0
>> dc := make(chan bool, worker)
>> for i := 0; i < worker; i++ {
>> go do(i, rc, dc)
>> }
>> for done < worker {
>> r := <-rc
>> fmt.Println(r)
>> <-dc
>> done++
>> }
>> }
>>
>>
>> On Tue, Dec 18, 2018 at 5:35 AM Chris Burkert 
>> wrote:
>>
>>> Dear all,
>>>
>>> I have a couple of goroutines sending multiple results over a channel -
>>> a simple fan-in. They signal the completion on a done channel. Main selects
>>> on the results and done channel in parallel. As the select is random main
>>> sometimes misses to select the last result. What would be the idiomatic way
>>> to prevent this and completely drain the result channel?
>>>
>>> Here is a minmal example which sometimes prints one 0 but should always
>>> print two of them:
>>>
>>> package main
>>>
>>> import (
>>> "fmt"
>>> )
>>>
>>> func do(rc chan<- int, dc chan<- bool) {
>>> rc <- 0
>>> dc <- true
>>> }
>>>
>>> func main() {
>>> worker

Re: [go-nuts] Channels: selecting the last element

2018-12-18 Thread Chris Burkert
Now I got it - thanks for the explanation.

Am Mi., 19. Dez. 2018 um 02:25 Uhr schrieb :

> > feel unbuffered channels are safer to use especially in an acyclic
> directed graph of flowing values. Buffered channels seem to reduce blocking
> but I feel they come with the cost of such side effects like my initial
> problem of forgotten results in their channels.
>
>
> that happens with unbuffered channel too, if, for example, you mix it with
> a select on context cancellation.
> Maybe you are lucky and your data source provides a acknowledgment
> mechanism, maybe you are not and it s up to you to work around.
> This becomes a problem when the code can t be rationalized via an api that
> is able to wrap those behaviors.
>
> On Tuesday, December 18, 2018 at 8:50:20 PM UTC+1, Chris Burkert wrote:
>>
>> Robert,
>> it seems to me that you have a clear understanding about unbuffered vs.
>> buffered channels. I feel unbuffered channels are safer to use especially
>> in an acyclic directed graph of flowing values. Buffered channels seem to
>> reduce blocking but I feel they come with the cost of such side effects
>> like my initial problem of forgotten results in their channels. I would
>> love to hear/read/see more on the unbuffered vs. buffered tradeoff to get
>> rid of this gut feeling I am currently based on :-). Any good article you
>> can point me to?
>> Thanks
>>
>> Robert Engels  schrieb am Di. 18. Dez. 2018 um
>> 17:03:
>>
>>> That code is incorrect as well when using buffered channels.
>>>
>>> On Dec 18, 2018, at 10:00 AM, Skip Tavakkolian 
>>> wrote:
>>>
>>> why not just  drop the select? i think the following is guaranteed
>>> because putting things on rc has to succeed before putting true into dc:
>>>
>>> package main
>>>
>>> import (
>>> "fmt"
>>> )
>>>
>>> func do(i int, rc chan<- int, dc chan<- bool) {
>>> rc <- i
>>> dc <- true
>>> }
>>>
>>> func main() {
>>> worker := 10
>>> rc := make(chan int, worker)
>>> done := 0
>>> dc := make(chan bool, worker)
>>> for i := 0; i < worker; i++ {
>>> go do(i, rc, dc)
>>> }
>>> for done < worker {
>>> r := <-rc
>>> fmt.Println(r)
>>> <-dc
>>> done++
>>> }
>>> }
>>>
>>>
>>> On Tue, Dec 18, 2018 at 5:35 AM Chris Burkert 
>>> wrote:
>>>
>>>> Dear all,
>>>>
>>>> I have a couple of goroutines sending multiple results over a channel -
>>>> a simple fan-in. They signal the completion on a done channel. Main selects
>>>> on the results and done channel in parallel. As the select is random main
>>>> sometimes misses to select the last result. What would be the idiomatic way
>>>> to prevent this and completely drain the result channel?
>>>>
>>>> Here is a minmal example which sometimes prints one 0 but should always
>>>> print two of them:
>>>>
>>>> package main
>>>>
>>>> import (
>>>> "fmt"
>>>> )
>>>>
>>>> func do(rc chan<- int, dc chan<- bool) {
>>>> rc <- 0
>>>> dc <- true
>>>> }
>>>>
>>>> func main() {
>>>> worker := 2
>>>> rc := make(chan int, worker)
>>>> done := 0
>>>> dc := make(chan bool, worker)
>>>> for i := 0; i < worker; i++ {
>>>> go do(rc, dc)
>>>> }
>>>> for done < worker {
>>>> select {
>>>> case <-dc:
>>>> done++
>>>> case r := <-rc:
>>>> fmt.Println(r)
>>>> }
>>>> }
>>>> }
>>>>
>>>> many thanks
>>>> Chris
>>>>
>>>> --
>>>> 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.
>>>> 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...@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.
>

-- 
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] Channels: selecting the last element

2018-12-18 Thread Chris Burkert
Robert,
it seems to me that you have a clear understanding about unbuffered vs.
buffered channels. I feel unbuffered channels are safer to use especially
in an acyclic directed graph of flowing values. Buffered channels seem to
reduce blocking but I feel they come with the cost of such side effects
like my initial problem of forgotten results in their channels. I would
love to hear/read/see more on the unbuffered vs. buffered tradeoff to get
rid of this gut feeling I am currently based on :-). Any good article you
can point me to?
Thanks

Robert Engels  schrieb am Di. 18. Dez. 2018 um 17:03:

> That code is incorrect as well when using buffered channels.
>
> On Dec 18, 2018, at 10:00 AM, Skip Tavakkolian 
> wrote:
>
> why not just  drop the select? i think the following is guaranteed because
> putting things on rc has to succeed before putting true into dc:
>
> package main
>
> import (
> "fmt"
> )
>
> func do(i int, rc chan<- int, dc chan<- bool) {
> rc <- i
> dc <- true
> }
>
> func main() {
> worker := 10
> rc := make(chan int, worker)
> done := 0
> dc := make(chan bool, worker)
> for i := 0; i < worker; i++ {
> go do(i, rc, dc)
> }
> for done < worker {
> r := <-rc
> fmt.Println(r)
> <-dc
> done++
> }
> }
>
>
> On Tue, Dec 18, 2018 at 5:35 AM Chris Burkert 
> wrote:
>
>> Dear all,
>>
>> I have a couple of goroutines sending multiple results over a channel - a
>> simple fan-in. They signal the completion on a done channel. Main selects
>> on the results and done channel in parallel. As the select is random main
>> sometimes misses to select the last result. What would be the idiomatic way
>> to prevent this and completely drain the result channel?
>>
>> Here is a minmal example which sometimes prints one 0 but should always
>> print two of them:
>>
>> package main
>>
>> import (
>> "fmt"
>> )
>>
>> func do(rc chan<- int, dc chan<- bool) {
>> rc <- 0
>> dc <- true
>> }
>>
>> func main() {
>> worker := 2
>> rc := make(chan int, worker)
>> done := 0
>> dc := make(chan bool, worker)
>> for i := 0; i < worker; i++ {
>> go do(rc, dc)
>> }
>> for done < worker {
>> select {
>> case <-dc:
>> done++
>> case r := <-rc:
>> fmt.Println(r)
>> }
>> }
>> }
>>
>> many thanks
>> Chris
>>
>> --
>> 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 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 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] Channels: selecting the last element

2018-12-18 Thread Chris Burkert
Justin,
I don‘t understand that. Maybe I am wrong but I think this is not an issue
anymore with the wait group as Ian proposed. It fully replaces the done
channel by closing all result channels while the select keeps on reading
from the result channels until they are all closed and empty. Please
correct me if I am wrong.
Chris

Justin Israel  schrieb am Di. 18. Dez. 2018 um
19:08:

>
>
> On Wed, Dec 19, 2018, 5:31 AM Chris Burkert 
> wrote:
>
>> Hello Ian, all,
>> yes, the workers generate multiple results. I was able to use your
>> proposal with the waiting goroutine which closes the channel. Unfortunately
>> my initial minimal example was not so minimal. It is a little more
>> complicated, as I have multiple "result" channels with different types and
>> I don't know how many values I get. So I can't just range over one channel
>> but instead use select with the ok from "val, ok := <-channel" to count the
>> closed channels which finally ends the loop. Below is what I came up with
>> (using Johns approach to run it multiple times) and it seems to be
>> deterministic.
>> Many thanks!
>> PS: with buffered channels I have to disable closed channels with
>> "channel = nil" to make it work.
>>
>
> You should need to disable the closed channel by setting it nil regardless
> of it being buffered or not. Depending on how you actually end up sending
> results back on multiple channels it could still be a bug if you end up
> selecting on the closed channel multiple times and think you are done
> instead of reading from another channel with results.
>
>
>> package main
>>
>> import (
>> "fmt"
>> "sync"
>> )
>>
>> func do(fc chan<- int, rc chan<- string) {
>> fc <- 42
>> fc <- 43
>> rc <- "foo"
>> }
>>
>> func main() {
>> w := 4
>> r := 10
>> n := 0
>> for i := 0; i < r; i++ {
>> n = n + run(w)
>> }
>> fmt.Printf("Got %d, expected %d\n", n, 3*w*r)
>> }
>>
>> func run(worker int) int {
>> fc := make(chan int)
>> rc := make(chan string)
>> var wg sync.WaitGroup
>> wg.Add(worker)
>> for i := 0; i < worker; i++ {
>> go func() {
>> defer wg.Done()
>> do(fc, rc)
>> }()
>> }
>> go func() {
>> wg.Wait()
>> close(fc)
>> close(rc)
>> }()
>> n := 0
>> closed := 0
>> for closed < 2 {
>> select {
>> case _, ok := <-fc:
>> if ok {
>> n++
>>         } else {
>> closed++
>> }
>> case _, ok := <-rc:
>> if ok {
>> n++
>> } else {
>> closed++
>> }
>> }
>> }
>> return n
>> }
>>
>> Am Di., 18. Dez. 2018 um 15:50 Uhr schrieb Ian Lance Taylor <
>> i...@golang.org>:
>>
>>> On Tue, Dec 18, 2018 at 5:35 AM Chris Burkert 
>>> wrote:
>>> >
>>> > I have a couple of goroutines sending multiple results over a channel
>>> - a simple fan-in. They signal the completion on a done channel. Main
>>> selects on the results and done channel in parallel. As the select is
>>> random main sometimes misses to select the last result. What would be the
>>> idiomatic way to prevent this and completely drain the result channel?
>>> >
>>> > Here is a minmal example which sometimes prints one 0 but should
>>> always print two of them:
>>> >
>>> > package main
>>> >
>>> > import (
>>> > "fmt"
>>> > )
>>> >
>>> > func do(rc chan<- int, dc chan<- bool) {
>>> > rc <- 0
>>> > dc <- true
>>> > }
>>> >
>>> > func main() {
>>> > worker := 2
>>> > rc := make(chan int, worker)
>>> > done := 0
>>> > dc := make(chan bool, worker)
&g

Re: [go-nuts] Channels: selecting the last element

2018-12-18 Thread Chris Burkert
Hello Ian, all,
yes, the workers generate multiple results. I was able to use your proposal
with the waiting goroutine which closes the channel. Unfortunately my
initial minimal example was not so minimal. It is a little more
complicated, as I have multiple "result" channels with different types and
I don't know how many values I get. So I can't just range over one channel
but instead use select with the ok from "val, ok := <-channel" to count the
closed channels which finally ends the loop. Below is what I came up with
(using Johns approach to run it multiple times) and it seems to be
deterministic.
Many thanks!
PS: with buffered channels I have to disable closed channels with "channel
= nil" to make it work.

package main

import (
"fmt"
"sync"
)

func do(fc chan<- int, rc chan<- string) {
fc <- 42
fc <- 43
rc <- "foo"
}

func main() {
w := 4
r := 10
n := 0
for i := 0; i < r; i++ {
n = n + run(w)
}
fmt.Printf("Got %d, expected %d\n", n, 3*w*r)
}

func run(worker int) int {
fc := make(chan int)
rc := make(chan string)
var wg sync.WaitGroup
wg.Add(worker)
for i := 0; i < worker; i++ {
go func() {
defer wg.Done()
do(fc, rc)
}()
}
go func() {
wg.Wait()
close(fc)
close(rc)
}()
n := 0
closed := 0
for closed < 2 {
select {
case _, ok := <-fc:
if ok {
n++
} else {
closed++
}
case _, ok := <-rc:
if ok {
n++
} else {
closed++
}
}
}
return n
}

Am Di., 18. Dez. 2018 um 15:50 Uhr schrieb Ian Lance Taylor :

> On Tue, Dec 18, 2018 at 5:35 AM Chris Burkert 
> wrote:
> >
> > I have a couple of goroutines sending multiple results over a channel -
> a simple fan-in. They signal the completion on a done channel. Main selects
> on the results and done channel in parallel. As the select is random main
> sometimes misses to select the last result. What would be the idiomatic way
> to prevent this and completely drain the result channel?
> >
> > Here is a minmal example which sometimes prints one 0 but should always
> print two of them:
> >
> > package main
> >
> > import (
> > "fmt"
> > )
> >
> > func do(rc chan<- int, dc chan<- bool) {
> > rc <- 0
> > dc <- true
> > }
> >
> > func main() {
> > worker := 2
> > rc := make(chan int, worker)
> > done := 0
> > dc := make(chan bool, worker)
> > for i := 0; i < worker; i++ {
> > go do(rc, dc)
> > }
> > for done < worker {
> > select {
> > case <-dc:
> > done++
> > case r := <-rc:
> > fmt.Println(r)
> > }
> > }
> > }
>
>
> I assume the workers can generate multiple results, as otherwise the
> done marker seems pointless.  In general the simplest way to signal
> completion on a channel is to call close.  The simplest way to call
> close on a fan-in is to have another goroutine that waits for the
> other goroutines and closes the channel.  That might look like
>
> package main
>
> import (
> "fmt"
> "sync"
> )
>
> func do(rc chan<- int) {
> rc <- 0
> }
>
> func main() {
> worker := 2
> rc := make(chan int, worker)
> var wg sync.WaitGroup
> wg.Add(worker)
> for i := 0; i < worker; i++ {
> go func() {
> defer wg.Done()
> do(rc)
> }()
> }
> go func() {
> wg.Wait()
> close(rc)
> }()
> for r := range rc {
> fmt.Println(r)
> }
> }
>
> Ian
>

-- 
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] Channels: selecting the last element

2018-12-18 Thread Chris Burkert
Dear all,

I have a couple of goroutines sending multiple results over a channel - a
simple fan-in. They signal the completion on a done channel. Main selects
on the results and done channel in parallel. As the select is random main
sometimes misses to select the last result. What would be the idiomatic way
to prevent this and completely drain the result channel?

Here is a minmal example which sometimes prints one 0 but should always
print two of them:

package main

import (
"fmt"
)

func do(rc chan<- int, dc chan<- bool) {
rc <- 0
dc <- true
}

func main() {
worker := 2
rc := make(chan int, worker)
done := 0
dc := make(chan bool, worker)
for i := 0; i < worker; i++ {
go do(rc, dc)
}
for done < worker {
select {
case <-dc:
done++
case r := <-rc:
fmt.Println(r)
}
}
}

many thanks
Chris

-- 
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] Force pointer at compile time to interface{} parameter

2018-11-19 Thread Chris Burkert
Hello Hay,
with interface{} you explicitly allow everything. Instead you may consider
to restrict the accepted input in the first place - e.g. with a non-empty
interface.
Chris

hay  schrieb am Mo. 19. Nov. 2018 um 15:37:

> Hi,
>
> I've the following example code of correct version.
>
> func SomeFunction(itemPtr interface{}) {
>
>
> //itemPtr must be pointer to struct and not struct.
>
>
> }
>
>
> func SomeFunctionCaller() {
>
>
> u := UserRecord{}
>
>
> SomeFunction()
>
>
> }
>
>
> Above is the correct version, but some coders pass struct instead of
> pointer which causes run-time errors.
>
> Bad version:
>
> func SomeFunctionCaller() {
>
>
> u := UserRecord{}
>
>
> SomeFunction(u)
>
>
> }
>
>
> Is there a way to force "SomeFunction" to take pointers only at compile
> time?
>
> Thanks and best regards,
>
> --
> 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 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] Directory Structure in Markdown Synax

2018-10-29 Thread Chris Burkert
Maybe episode #35 from justforfunc (https://youtu.be/XbKSssBftLM) answers
what you’re searching for.

Alex Dvoretskiy  schrieb am Mo. 29. Okt. 2018 um
20:21:

> Looking for a Go code or algorithm, in general, to print out directory
> structure.
>
> Example: https://jekyllrb.com/docs/structure/
>
> . ├── _config.yml ├── _data | └── members.yml ├── _drafts | ├──
> begin-with-the-crazy-ideas.md | └── on-simplicity-in-technology.md ├──
> _includes | ├── footer.html | └── header.html ├── _layouts | ├──
> default.html | └── post.html ├── _posts | ├──
> 2007-10-29-why-every-programmer-should-play-nethack.md | └──
> 2009-04-26-barcamp-boston-4-roundup.md ├── _sass | ├── _base.scss | └──
> _layout.scss ├── _site ├── .jekyll-metadata └── index.html
>
> --
> 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 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] cgo and time.After

2018-05-20 Thread Chris Burkert
Dear Jakob and all,

indeed I was blind. This works like a charm:
amount := 42
remaining := amount
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
for remaining > 0 {
select {
case <-ticker.C:
fmt.Printf("Progress: %d left from %d\n", remaining, amount)
case <-donChan:
remaining--
case res := <-resChan:
fmt.Println(res)
}
}

thanks all!
Chris

On Saturday, May 19, 2018 at 9:16:19 PM UTC+2, Jakob Borg wrote:
>
> On 19 May 2018, at 16:25, Chris Burkert <burker...@gmail.com > 
> wrote: 
> > 
> > case <-time.After(5 * time.Second): 
> > fmt.Printf("Progress: %d left from %d\n", remaining, amount) 
>
> It's not super clear from your post if you're aware of this already, but 
> this case will only fire after the select has been blocked for five 
> seconds. If there is any activity on the other cases one of those will 
> proceed, you'll get another loop iteration, and another five second timeout 
> before status output. 
>
> Typically you'd use a five second ticker instead to get a channel event 
> every five seconds and use that to print status output. 
>
> //jb

-- 
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] cgo and time.After

2018-05-19 Thread Chris Burkert
Jakob, I think you’re right. I am going to test this as soon as I am back
home. After all I am a beginner in this area and it seems this one fooled
me. I’ll send an update tomorrow.
thanks - Chris

Jakob Borg <ja...@kastelo.net> schrieb am Sa. 19. Mai 2018 um 21:15:

> On 19 May 2018, at 16:25, Chris Burkert <burkert.ch...@gmail.com> wrote:
> >
> > case <-time.After(5 * time.Second):
> > fmt.Printf("Progress: %d left from %d\n", remaining, amount)
>
> It's not super clear from your post if you're aware of this already, but
> this case will only fire after the select has been blocked for five
> seconds. If there is any activity on the other cases one of those will
> proceed, you'll get another loop iteration, and another five second timeout
> before status output.
>
> Typically you'd use a five second ticker instead to get a channel event
> every five seconds and use that to print status output.
>
> //jb

-- 
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] cgo and time.After

2018-05-19 Thread Chris Burkert
Dear Gophers,

I am working on a small database tool which checks a database for 
inconsistencies. It does that by calling a stored procedure via sql. 
Unfortunately the database client is available as C-library only but 
luckily there is a go driver for the database/sql package so at least it 
feels like pure go. Of course it is not as it uses cgo under the hood. 
After all I got the basics working based on the following:

   1. a producer goroutine reads from the database, creates the sql 
   statements to be run and passes them into a task channel
   2. eight worker goroutines read from the task channel, run one task at a 
   time on the database and pass the result to a results channel (resChan)
   3. main reads the results from the results channel

So far, so good. Then I wanted to add some progress info. As I know the 
number of checks I added another channel (donChan). Each worker goroutine 
sends an empty struct on that channel after a check has been finished. main 
reads from that channel and decreases the remaining number of checks.

In the end I have something like this:
amount := 42
remaining := amount
for remaining > 0 {
select {
case <-time.After(5 * time.Second):
fmt.Printf("Progress: %d left from %d\n", remaining, amount)
case <-donChan:
remaining--
case res := <-resChan:
fmt.Println(res)
}
}

This is simplified but I hope you get the idea.

The effect is that as long as the eight worker and the producer goroutines 
are running and using the database, I don't see the progress message which 
should be triggered by time.After. To me it looks like the runtime is busy 
with the large cgo threads and cannot handle/schedule the time.After 
goroutine. But when I raise variable amount for testing while the number of 
actual checks is lower (then the for look will run forever) I see the 
Progress output as soon as the worker and the producer goroutines are done. 
So the time.After is not dead - it's just blocked while cgo is used.

And here I would like to ask you for tips and help. If you have an idea and 
you need more details please let me know.

I also came across Dave Cheneys 
post https://dave.cheney.net/2016/01/18/cgo-is-not-go and I believe this is 
what I am suffering from. Unfortunately there is no other database client 
available. It is about SAPs database HANA and I know there is a pure go 
implementation. Unfortunately this one lacks hdbuserstore support which is 
some kind of password store for HANA I need. So I have to use the official 
HANA client based on the C-library.

thanks for any help!
Chris
PS: I am using go 1.10.2 and also tried 1.10 with the same result

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