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

2023-06-10 Thread quin...@gmail.com
there has been much discussion in the past about programs that modify their 
behaviour depending on what stdout is; 
http://harmful.cat-v.org/cat-v/unix_prog_design.pdf

i do to want to start a war, just suggest a different approach is available.

my suggestion would be to always expect a password from standard input and 
to do document this, suggesting, for non-interactive use people could do 
something like:

 echo password | application

using environment variables or passing passwords on the command line are 
rather leaky.

-Steve



On Friday, 9 June 2023 at 00:52:58 UTC+1 Rich wrote:

> Thank you Cris and Kurtis -- For this project I am going with the switch 
> option -- but I have other programs that I am going to replace the 
> os.Getpid and os.Getppid trick with go-isatty.
>
>
>
> On Thursday, June 8, 2023 at 3:22:29 PM UTC-4 Chris Burkert wrote:
>
>> 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...@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/b5285e0c-51bf-4ec5-8682-70b5a324c32bn%40googlegroups.com.


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

2023-02-08 Thread quin...@gmail.com

Thanks for the ideas all, I think go embed is the best path for me.

runtime/debug will give me the revision but sadly it can't give me the 
branch.

I want the branch as we run a microservice architecture and seeing that all 
the microservices are running
the release branch and not master (or main) is a useful cross check for our 
QA dept; we have had cases of
them spending time checking development code which is - well, imperfect.

-Steve

On Tuesday, 7 February 2023 at 16:37:16 UTC klau...@schwarzvogel.de wrote:

> Hi! 
>
> On Mon, 06 Feb 2023, quin...@gmail.com wrote:
> > 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?
>
> Indeed there is. On top of the already mentioned approaches using go
> generate, the runtime/debug package:
>
> ```
> import "runtime/debug"
>
> var Commit = func() string {
> if info, ok := debug.ReadBuildInfo(); ok {
> for _, setting := range info.Settings {
> if setting.Key == "vcs.revision" {
> return setting.Value
> }
> }
> }
> return ""
> }()
> ```
>
> (shamelessly stolen from
>
> https://icinga.com/blog/2022/05/25/embedding-git-commit-information-in-go-binaries/
> )
>
> HTH,
> Tobias
>

-- 
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/b53d020d-147e-4a34-9ce9-d5efbc185b99n%40googlegroups.com.


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

2023-02-06 Thread quin...@gmail.com

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.


[go-nuts] package private variables for singleton packages - good/bad style

2022-05-13 Thread quin...@gmail.com
Hi,

I have 3 years of experience writing go, but decades of writing C. I am 
reaching for best practices on using package private variables to implement 
signleton packages.

I work on a fairly large microservice project which uses protobufs over 
NATS for communication and ETCd for a key/val store etc. We have put 
together a repository of packages (a lbrary in C terms) of microservice 
support tools which mop up much common code in the microservices.

There is a precident for implementing such libraries using a package 
private variable to store the package's state (singletons) - the obvious 
example is log 
(https://cs.opensource.google/go/go/+/refs/tags/go1.18.2:src/log/log.go 
line 87, var std)

Doing this means our microservice code is a little cleaner but does hide 
some non-obvious "magic" in the library. The alternative is the 
microservices all need to create a set of global variables for the packages 
they reference and use those; which feels like unnecessary syntactic sugar.

I understand that this technique restricts the package to a single 
instance, however in this case this is fine; we never need more than one 
connection to NATS or ETCd.

I have read various blogs which argue one way or the other, do the Go 
authors (or any other esteemed authority) have any strong opinions to 
offer? Am I committing a crime against go, or am I using the power of the 
language to cleanly implement a feature?

-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/604d970c-a776-4e36-8ba3-788a4bb1b9fen%40googlegroups.com.


[go-nuts] HPC image processing in go?

2021-11-04 Thread quin...@gmail.com
Hi,

Has anyone got any experience of high performance image processing in go?

By this I mean doing complex image processing in real time at 4K resolution 
on commodity hardware. This is really pushing it using carefully written 
C++ but when we tried writing similar code using go slices we go a 
significant slowdown (x4 over gcc).

We experimented using unsafe pointers thinking it is go's slice range 
checking that cause the problems, but surprisingly saw no improvement.

Has anyone had success saturating the memory bandwidth using go?  Is my 
result a surprise to people? Is it just that gcc's code generator is very 
mature and Go's is less so, or should I keep looking for dropoffs in my 
code?

I haven't looked at the generated assembly yet, but that is my next step.

Any opinions?

-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/8419a816-8058-48c1-874b-09a34be0f3fcn%40googlegroups.com.


Re: [go-nuts] comment conversion script? inlncmt.awk?

2020-10-02 Thread quin...@gmail.com

inlncmt.awk was my joke-ey guess at what such a thing might be called,
but gofmtcomment 
<https://pkg.go.dev/github.com/shuLhan/share/cmd/gofmtcomment> sounds just 
like what I want.

Many thanks,

-Steve

On Friday, 2 October 2020 at 12:02:11 UTC+1 Shulhan wrote:

>
>
> > On 2 Oct 2020, at 15.05, quin...@gmail.com  wrote:
> > 
> > Hi,
> > 
> > When I was writing C I used to use a script bcmt.awk (it might have been 
> one of russ's or erikQ's, I cannot remember) to convert c++ style comments 
> to K syle. Now I am a proud go programmer I find my fingers still want to 
> put starts before and after my slashes when writing comments.
> > 
> > Has anyone written inlncmt.awk or similar to help me fix my poor style? 
> Though this may sound simple it needs care to deal with /* and */ in 
> strings and multiline comments nicely. This is why I ask.
> > 
>
> I am not familiar with inlncmt.awk, did you mean a tools to convert from 
> "/**/" to "//" ?
> If yes, I have gofmtcomment [1].
>
> [1] https://pkg.go.dev/github.com/shuLhan/share/cmd/gofmtcomment
>
>

-- 
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/c4b7173d-467e-4638-ab10-8dc0230c3f35n%40googlegroups.com.


[go-nuts] comment conversion script? inlncmt.awk?

2020-10-02 Thread quin...@gmail.com
Hi,

When I was writing C I used to use a script bcmt.awk (it might have been 
one of russ's or erikQ's, I cannot remember) to convert c++ style comments 
to K syle. Now I am a proud go programmer I find my fingers still want to 
put starts before and after my slashes when writing comments.

Has anyone written inlncmt.awk or similar to help me fix my poor style? 
Though this may sound simple it needs care to deal with /* and */ in 
strings and multiline comments nicely. This is why I ask.

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/3564eccc-9a62-4f5f-8982-c762e3668070n%40googlegroups.com.