[go-nuts] Re: Discover go-size-analyzer: Streamline Your Go Binary Insights

2024-05-22 Thread Peter Galbavy
Another thumbs up! Thanks

On Tuesday 21 May 2024 at 16:16:54 UTC+1 Zxilly Chou wrote:

> Hello go-nuts,
>
> I'm excited to share a new tool that has landed in our Go ecosystem: 
> go-size-analyzer. This utility is designed to give you a clear picture of 
> the size of your compiled Go binaries, with a focus on how dependencies 
> contribute to the overall footprint.
>
> It simplifies the process of binary size analysis and offers a range of 
> viewing options, from web interfaces to terminal UIs and text formats. It's 
> also highly customisable, so you can tailor the output to suit your needs.
>
> The project is open source and actively seeking contributions, so if 
> you're interested in this kind of tool, it's definitely worth a look.
>
> You can find more information and get started with go-size-analyzer on its 
> GitHub page: https://github.com/Zxilly/go-size-analyzer
>
> Happy coding!
>
> Best,
>
> Zxilly
>

-- 
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/c40129f5-9ae9-4ce2-a218-8943ad948cadn%40googlegroups.com.


Re: [go-nuts] xml to json, parsing xml

2024-04-25 Thread Peter Galbavy
I could really have used the go-xmlstruct a year ago :-) But, if I need to 
fill in more blanks I will try it!

On Thursday 25 April 2024 at 02:24:45 UTC+1 twp...@gmail.com wrote:

> You can parse XML and JSON quickly with these tools:
>
> https://github.com/twpayne/go-xmlstruct
> https://github.com/twpayne/go-jsonstruct
>
> They generate Go code that parses all the example XML and JSON files that 
> you throw at them.
>
> Regards,
> Tom
>
> On Tuesday, April 23, 2024 at 9:17:33 PM UTC+2 Don Caldwell wrote:
>
>> Oops, I didn't look carefully at the json output of my little program. It 
>> does sometimes emit arrays. For example:
>>
>> go build xmlparse.go
>>
>> ./xmlparse -url 'https://news.google.com/atom'
>>
>>
>> This produces what, for some part, represents acceptable json. The 
>> exceptions are the atom entries that would still require, I think, another 
>> pass to fix up the go structure unless someone applies a priori knowledge 
>> of the xml structure when building it.
>>
>>
>> D
>>
>>
>>
>> D
>>
>>
>> D
>>
>> On Tue, Apr 23, 2024 at 1:18 PM Don Caldwell  wrote:
>>
>>> I agree. The link that I sent demonstrates one very simple way. Mapping 
>>> XML with repetitive tag sets to JSON arrays, though, would take a bit of 
>>> work meaning, I think, at least two passes.
>>>
>>> D
>>>
>>> On Tue, Apr 23, 2024, 13:04 robert engels  wrote:
>>>
 I don’t think that is true. There are multiple ways to model XML into 
 json.

 See this http://badgerfish.ning.com for one of them.

 On Apr 23, 2024, at 11:43 AM, burak serdar  wrote:

 In general, you cannot convert xml to json. They have incompatible
 models. XML elements are ordered similar to a JSON array, but in many
 cases you want to map XML elements to JSON objects, which are
 unordered name-value collections. Also, there is no JSON equivalent of
 an XML attribute.

 If you want to work with XML, either use xml marshaling, or find a
 third-party DOM library.

 On Tue, Apr 23, 2024 at 10:29 AM Don Caldwell  wrote:


 Disclaimer - I am very new to golang.
 I puzzled about this for a few days. After some struggle, I got a 
 little program working that parses
 arbitrary xml into a structure that json can understand. You can find 
 it here:
 https://github.com/dfwcnj/gxmldecode

 On Thursday, October 7, 2021 at 10:06:30 AM UTC-4 RS wrote:


 What is the best approach to convert xml to json?
 However I need above all to parse a very complex xml to see if related 
 properties are existing.
 I thought maybe converting it to Json maybe make it easier.


 --
 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/90c0dd22-2d81-4393-b534-651a2376f386n%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/CAMV2RqowOgbOnmGxsWegOuJ-_crQcNhsjj1Gxk3pAXhBmtNK5Q%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/264ceec0-e2fb-4965-ae8b-839763730f75n%40googlegroups.com.


[go-nuts] Re: regexp docs for 'Index' ?

2023-12-14 Thread Peter Galbavy
Ah! My bad. I misread the docs - "result" is the input, while the "n" 
indexes are actually the values of the submatches, not the indexes. I still 
think it's confusing, but makes more sense when I write it like this: 
https://go.dev/play/p/SHl_aSU3kPZ 

On Thursday 14 December 2023 at 09:06:00 UTC Brian Candler wrote:

> [a:b] gives you the elements from a to b-1 inclusive. So if you want the 
> pair at position x, it has to be [x:x+2]
>
> https://go.dev/play/p/3nvEfOjdfnj
>
> On Thursday 14 December 2023 at 08:38:57 UTC Peter Galbavy wrote:
>
>> I noticed today that the regexp docs read:
>>
>> If 'Index' is present, matches and submatches are identified by byte 
>> index pairs within the input string: result[2*n:2*n+2] identifies the 
>> indexes of the nth submatch. 
>>
>> I think that should be result[2*n:2*n+1] - at least in my code that's how 
>> it is working.
>>
>> If I'm right, happy to raise a doc bug, but never done that, so not sure 
>> how - for a one digit change?
>>
>> Peter
>>
>

-- 
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/d67d1a02-e919-4118-9718-012e6497814cn%40googlegroups.com.


[go-nuts] regexp docs for 'Index' ?

2023-12-14 Thread Peter Galbavy
I noticed today that the regexp docs read:

If 'Index' is present, matches and submatches are identified by byte index 
pairs within the input string: result[2*n:2*n+2] identifies the indexes of 
the nth submatch. 

I think that should be result[2*n:2*n+1] - at least in my code that's how 
it is working.

If I'm right, happy to raise a doc bug, but never done that, so not sure 
how - for a one digit change?

Peter

-- 
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/6d84a903-2584-4eab-b2f2-974fdf9228b8n%40googlegroups.com.


[go-nuts] Re: Interface in factory pattern and binary size increasing

2023-11-08 Thread Peter Galbavy
Check the size of dependencies; 
>From 
>https://stackoverflow.com/questions/70764915/how-to-check-the-size-of-packages-linked-into-my-go-code
> 
the very last answer suggests:

go tool nm -size -sort size EXECUTABLE

Which has helped me locate unexpected lumps of imports. You can also build 
with  --ldflags '-s -w' to remove debug symbols. If size is a concern for 
distribution, look at "upx" to compress the binary.
On Tuesday, 7 November 2023 at 13:42:42 UTC Xabi Martí wrote:

> Hi there, I've a problem with an increasing binary size and aws sdk.
>
> I'm developing a cobra application for certain aws services with aws sdk 
> v2, and I've a problem with a factory pattern, I've this code
> ```golang
> package ec2
>
> import (
> "github.com/aws/aws-sdk-go-v2/aws"
> "github.com/aws/aws-sdk-go-v2/service/ec2"
> )
>
> type EC2Interface interface {
> ListInstances() error
> GetInstanceID(instanceTagName string) (string, error)
> GetSecurityGroupsFrom(application string, environment string) ([]string, 
> error)
> GetSubnetsFromPrefix(prefix string) ([]string, error)
> }
>
> type EC2Client struct {
> client *ec2.Client
> }
>
> func NewEC2Client(awscfg aws.Config) (*EC2Client, error) {
> client := ec2.NewFromConfig(awscfg)
> return {client: client}, nil
> }
> ```
>
> Here I'm returning the `*EC2Client` and I'm creating the client like this
> ```golang
>
> ec2Client, err := ec2.NewEC2Client(awscfg)
> if err != nil {
> errors.CaptureException(err)
> }
> ```
> and calling it later functions like this
> ```golang
> err = whatever.ExecuteOperation(*ecsClient, *ec2Client, *cwClient, 
> project, env, command, "operations", maxRetries, secondsForRetry, 
> synchronous, true, parsedEnvVars, servicesAsContainers)
> ```
>
>
> so, I decided to use the Interface for the `NewEC2Client` and all the 
> other clients (we use the same pattern with the other clients),
> ```golang
> package ec2
>
> import (
> "context"
>
> "github.com/aws/aws-sdk-go-v2/config"
> "github.com/aws/aws-sdk-go-v2/service/ec2"
> )
>
> type EC2Client interface {
> ListInstances() error
> GetInstanceID(instanceTagName string) (string, error)
> GetSecurityGroupsFrom(application string, environment string) ([]string, 
> error)
> GetSubnetsFromPrefix(prefix string) ([]string, error)
> }
>
> type awsEC2Client struct {
> client *ec2.Client
> }
>
> func NewEC2Client(profile string) (EC2Client, error) {
> awscfg, err := config.LoadDefaultConfig(
> context.Background(),
> config.WithSharedConfigProfile(profile),
> )
> if err != nil {
> return nil, err
> }
> client := ec2.NewFromConfig(awscfg)
> return {client: client}, nil
> }
> ```
> returning the Interface instead of the struct, for mocking, enforce the 
> contract, decouple, etc.. and call the implementation like this
> ```golang
>
> ec2Client, err := ec2.NewEC2Client(profile)
> if err != nil {
> errors.CaptureException(err)
> }
> ...
> err = whatever.ExecuteOperation(ecsClient, ec2Client, cwClient, project, 
> env, command, "operations", maxRetries, secondsForRetry, synchronous, true, 
> parsedEnvVars, servicesAsContainers)
> ```
>
> to the function
> ```golang
> func ExecuteOperation(ecsClient ecs.ECSClient, ec2Client ec2.EC2Client, 
> cwClient cloudwatch.CWClient, project, environment, command, container 
> string, maxRetries, secondsForRetry int, synchronous bool, notificationUser 
> bool, envVars map[string]string, servicesAsContainers bool) error {
> ```
>
>
> and it increase the size of the binary from 30Mb to 80Mb, I see the 
> attached with the go-binsize-treemap tool
>
> What is causing the increment of size? Any way to accomplish with the 
> interfaces without growing the binary size? Or should I remove the 
> interfaces as I'm not going to use any other implementation of the ec2 
> client?
>
> Thanks a lot
>

-- 
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/3a1fc0a8-1349-41f5-bed4-8773c37d7590n%40googlegroups.com.


[go-nuts] Re: Recommended way to distribute pre-compiled C-dependencies for modules using CGO ?

2023-10-11 Thread Peter Galbavy
Hang on - I missed your original statement that you are building 
*libraries* yourself. I am building executables. Sorry for the confusion 
and my too-fast scan reading!

On Wednesday, 11 October 2023 at 12:08:53 UTC+1 Peter Galbavy wrote:

> If you link statically, e.g. from my Dockerfile:
>
>   go build -tags netgo,osusergo --ldflags '-s -w -linkmode external 
> -extldflags=-static'
>
> then the libraries are in the single binary. I also then use "upx" to 
> compress the resulting binaries to save a little space. The build tags are 
> there to not require GLIBC for user and dns lookups.
>
>
>
> On Wednesday, 11 October 2023 at 11:43:20 UTC+1 Jan wrote:
>
>> Edit: ...so folks using your library don't need to install them manually 
>> ? What about uninstalling ?
>> On Wednesday, October 11, 2023 at 12:41:40 PM UTC+2 Jan wrote:
>>
>>> Thanks Peter, but I don't follow ... I also use docker to build the 
>>> pre-built binaries.
>>>
>>> But how do you distribute them, so folks using your library don't think 
>>> to install them ?
>>>
>>> On Wednesday, October 11, 2023 at 12:32:57 PM UTC+2 Peter Galbavy wrote:
>>>
>>>> I use a docker container (golang:bullseye seems the most compatible) 
>>>> and build static binaries. This is feasible as long as your dependencies 
>>>> do 
>>>> not require dynamic loading of dependencies.
>>>>
>>>> Poor (my Dockerfile skills) example here: 
>>>> https://github.com/ITRS-Group/cordial/blob/main/Dockerfile
>>>>
>>>> Peter
>>>>
>>>> On Wednesday, 11 October 2023 at 10:58:23 UTC+1 Jan wrote:
>>>>
>>>>> hi,
>>>>>
>>>>> I'm developing a couple of ML framework/libraries for Go that depend 
>>>>> on C/C++ code. Once C-libraries dependencies are installed, the CGO 
>>>>> integration work great.
>>>>>
>>>>> Now, for end-users that just want to use these Go libraries, having to 
>>>>> figure out how to manually build and install those C/C++/Rust 
>>>>> dependencies 
>>>>> is a hassle -- sadly each one with a different type of build system.
>>>>>
>>>>> I offer pre-built `.tgz` files (for a limited set of architectures) 
>>>>> with the required `.h` and `.a/.so` files along the releases, which 
>>>>> facilitates. But it's still a hassle to install -- and no auto-uninstall 
>>>>> if 
>>>>> someone is no longer using the Go module.
>>>>>
>>>>> I was wondering if others have figured out how to handle this in a 
>>>>> nicer way.  Is there a recommended way to distribute prebuilt CGO 
>>>>> dependencies ?
>>>>>
>>>>> I like how Python wheels (`.whl` files) solve the issue, by including 
>>>>> the pre-built libraries in a sub-directory of the python library 
>>>>> installation. I was hoping there would be a similar way (maybe with a 
>>>>> separate tool) to integrate with `go.mod`. 
>>>>>
>>>>> Any pointers, thoughts or suggestions are very appreciated.
>>>>>
>>>>> Thanks!
>>>>> Jan
>>>>>
>>>>> ps: While searching I saw similar questions, but none that exactly 
>>>>> answered this aspect of distribution. Just in case, apologies if it's a 
>>>>> duplicate question.
>>>>>
>>>>

-- 
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/c31db183-c69a-43e4-bee3-8f113d5e37c4n%40googlegroups.com.


[go-nuts] Re: Recommended way to distribute pre-compiled C-dependencies for modules using CGO ?

2023-10-11 Thread Peter Galbavy
If you link statically, e.g. from my Dockerfile:

  go build -tags netgo,osusergo --ldflags '-s -w -linkmode external 
-extldflags=-static'

then the libraries are in the single binary. I also then use "upx" to 
compress the resulting binaries to save a little space. The build tags are 
there to not require GLIBC for user and dns lookups.



On Wednesday, 11 October 2023 at 11:43:20 UTC+1 Jan wrote:

> Edit: ...so folks using your library don't need to install them manually ? 
> What about uninstalling ?
> On Wednesday, October 11, 2023 at 12:41:40 PM UTC+2 Jan wrote:
>
>> Thanks Peter, but I don't follow ... I also use docker to build the 
>> pre-built binaries.
>>
>> But how do you distribute them, so folks using your library don't think 
>> to install them ?
>>
>> On Wednesday, October 11, 2023 at 12:32:57 PM UTC+2 Peter Galbavy wrote:
>>
>>> I use a docker container (golang:bullseye seems the most compatible) and 
>>> build static binaries. This is feasible as long as your dependencies do not 
>>> require dynamic loading of dependencies.
>>>
>>> Poor (my Dockerfile skills) example here: 
>>> https://github.com/ITRS-Group/cordial/blob/main/Dockerfile
>>>
>>> Peter
>>>
>>> On Wednesday, 11 October 2023 at 10:58:23 UTC+1 Jan wrote:
>>>
>>>> hi,
>>>>
>>>> I'm developing a couple of ML framework/libraries for Go that depend on 
>>>> C/C++ code. Once C-libraries dependencies are installed, the CGO 
>>>> integration work great.
>>>>
>>>> Now, for end-users that just want to use these Go libraries, having to 
>>>> figure out how to manually build and install those C/C++/Rust dependencies 
>>>> is a hassle -- sadly each one with a different type of build system.
>>>>
>>>> I offer pre-built `.tgz` files (for a limited set of architectures) 
>>>> with the required `.h` and `.a/.so` files along the releases, which 
>>>> facilitates. But it's still a hassle to install -- and no auto-uninstall 
>>>> if 
>>>> someone is no longer using the Go module.
>>>>
>>>> I was wondering if others have figured out how to handle this in a 
>>>> nicer way.  Is there a recommended way to distribute prebuilt CGO 
>>>> dependencies ?
>>>>
>>>> I like how Python wheels (`.whl` files) solve the issue, by including 
>>>> the pre-built libraries in a sub-directory of the python library 
>>>> installation. I was hoping there would be a similar way (maybe with a 
>>>> separate tool) to integrate with `go.mod`. 
>>>>
>>>> Any pointers, thoughts or suggestions are very appreciated.
>>>>
>>>> Thanks!
>>>> Jan
>>>>
>>>> ps: While searching I saw similar questions, but none that exactly 
>>>> answered this aspect of distribution. Just in case, apologies if it's a 
>>>> duplicate question.
>>>>
>>>

-- 
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/dd567a9b-21a5-4621-a85d-06b33e70ad31n%40googlegroups.com.


[go-nuts] Re: Recommended way to distribute pre-compiled C-dependencies for modules using CGO ?

2023-10-11 Thread Peter Galbavy
I use a docker container (golang:bullseye seems the most compatible) and 
build static binaries. This is feasible as long as your dependencies do not 
require dynamic loading of dependencies.

Poor (my Dockerfile skills) example 
here: https://github.com/ITRS-Group/cordial/blob/main/Dockerfile

Peter

On Wednesday, 11 October 2023 at 10:58:23 UTC+1 Jan wrote:

> hi,
>
> I'm developing a couple of ML framework/libraries for Go that depend on 
> C/C++ code. Once C-libraries dependencies are installed, the CGO 
> integration work great.
>
> Now, for end-users that just want to use these Go libraries, having to 
> figure out how to manually build and install those C/C++/Rust dependencies 
> is a hassle -- sadly each one with a different type of build system.
>
> I offer pre-built `.tgz` files (for a limited set of architectures) with 
> the required `.h` and `.a/.so` files along the releases, which facilitates. 
> But it's still a hassle to install -- and no auto-uninstall if someone is 
> no longer using the Go module.
>
> I was wondering if others have figured out how to handle this in a nicer 
> way.  Is there a recommended way to distribute prebuilt CGO dependencies ?
>
> I like how Python wheels (`.whl` files) solve the issue, by including the 
> pre-built libraries in a sub-directory of the python library installation. 
> I was hoping there would be a similar way (maybe with a separate tool) to 
> integrate with `go.mod`. 
>
> Any pointers, thoughts or suggestions are very appreciated.
>
> Thanks!
> Jan
>
> ps: While searching I saw similar questions, but none that exactly 
> answered this aspect of distribution. Just in case, apologies if it's a 
> duplicate question.
>

-- 
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/f70dd0e8-6d21-4c36-a755-fdc52f9aff06n%40googlegroups.com.


[go-nuts] Re: Parsing difficult JSON

2023-09-14 Thread Peter Galbavy
You will need to create a custom type and unmarshal method. Plenty of 
example if you search for "golang custom json unmarshal".

As I've only had to implement it for a couple of simple types I can't offer 
my own valid example.

On Thursday, 14 September 2023 at 14:36:12 UTC+1 Tobias Klausmann wrote:

> Hi! 
>
> I am trying to write Prometheus exporter for stats queried fro the Kea
> DHCP server. Unfortunatly, the JSON is structured very badly if I want
> to use the base library JSON Unmarshal functionality:
>
> {
> "arguments": {
> "cumulative-assigned-addresses": [ [ 1, "2023-09-13 12:08:09.597483" ], 
> ... ],
> "pkt4-decline-received": [ [ 0, "2023-09-13 08:01:35.964113" ], ... ],
> "subnet[1].assigned-addresses": [ [ 1, "2023-09-13 08:01:36.014127" ], ... 
> ],
> "subnet[1].cumulative-assigned-addresses": [ [ 0, "2023-09-13 
> 08:01:36.014006" ], ... ],
> "subnet[1].declined-addresses": [ [ 0, "2023-09-13 08:01:36.014069" ], ... 
> ],
> "subnet[1].reclaimed-declined-addresses": [ [ 0, "2023-09-13 
> 08:01:36.014074" ], ... ],
> "subnet[1].reclaimed-leases": [ [ 0, "2023-09-13 08:01:36.014080" ], ... ],
> "subnet[1].total-addresses": [ [ 15, "2023-09-13 08:01:36.013997" ], ... ],
> "subnet[1].v4-reservation-conflicts": [ [ 0, "2023-09-13 08:01:36.014010" 
> ], ... ],
> "subnet[2].assigned-addresses": [ [ 4, "2023-09-14 13:32:20.906085" ], ... 
> ],
> "subnet[2].cumulative-assigned-addresses": [ [ 4, "2023-09-14 
> 13:32:20.906090" ], ... ],
> "subnet[2].declined-addresses": [ [ 0, "2023-09-13 08:01:36.014088" ], ... 
> ],
> "subnet[2].reclaimed-declined-addresses": [ [ 0, "2023-09-13 
> 08:01:36.014096" ], ... ],
> "subnet[2].reclaimed-leases": [ [ 3, "2023-09-14 00:08:10.270122" ], ... ],
> "subnet[2].total-addresses": [ [ 223, "2023-09-13 08:01:36.014015" ], ... 
> ],
> "subnet[2].v4-reservation-conflicts": [ [ 0, "2023-09-13 08:01:36.014025" 
> ], ... ],
> "subnet[3].assigned-addresses": [ [ 1, "2023-09-13 08:01:36.014135" ], ... 
> ]
> ... rest of subnet[3] and more subnets
> },
> "result": 0
> }
>
>
> The int, timestamp lists are already Not Great, but I can deal with
> those.
>
> The problem is the series of subnet[x] fields. They vary depending on
> how many subnets the server serves, and nothing in the JSON indicates
> how many there are. And even if it did: getting the stdlib JSON
> Unmarshaler to actually pick them up (without hardcoded struct tags)
> seems impossible, short of essentially writing my own JSON Unmarshaler
> from scratch.
>
> So I have three questions:
>
> 1. Am I missing some wildcard-ish functionality where I can tell the
> stdlib JSON Unmarshaler just make a slice out of all the JSON
> elements that fit a pattern?
> 2. Is there a Golang JSON library that is better suited to dealing with
> this?
> 3. What other options do I have (besides "use another
> language/exporter", "make upstream produce better JSON" and "write
> your own parser")?
>
> Best & TIA,
> 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/5e8cb3d6-7a46-48ca-a973-4f426fcb1be6n%40googlegroups.com.


[go-nuts] Re: go build of a *_unix.go file still used under windows ?

2023-09-01 Thread Peter Galbavy
After your initial reply and carefully re-reading I also agree that's what 
it means. It is however, IMHO, not clear on first reading and there is an 
implication by omission that "unix" could be considered a valid "GOOS" 
value. Now I know, I know. The next first-time reader, perhaps not so much.

Peter

On Thursday, 31 August 2023 at 11:11:06 UTC+1 Brian Candler wrote:

> During a particular build, the following build tags are satisfied:
>
>- ...
>- "unix", if GOOS is a Unix or Unix-like system.
>- ...
>
>
> It then says:
>
> If a file's name, after stripping the extension and a possible _test 
> suffix, matches any of the following patterns:
> *_GOOS *_GOARCH *_GOOS_GOARCH 
>
> (example: source_windows_amd64.go) where GOOS and GOARCH represent any 
> known operating system and architecture values respectively, then the file 
> is considered to have an implicit build constraint requiring those terms 
> (in addition to any explicit constraints in the file).
>
> This says that only GOOS and GOARCH are considered; it doesn't say that 
> all possible build tags are interpreted when in the filename, and indeed 
> there are many that are not.  For example, "foo_gccgo.go" and 
> "foo_go1.12.go" are not treated specially. So I think it's fairly clear 
> here, as long as you accept that "unix" is neither a GOOS nor a GOARCH.
>
> Aside: finding a comprehensive list of GOOS and GOARCH values is a bit 
> tricker. You can run "go tool dist list", or there are third-party 
> summaries like
> https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63
>
> On Thursday, 31 August 2023 at 10:44:14 UTC+1 Peter Galbavy wrote:
>
>> Ah! Got it. Thanks.
>>
>> Would it perhaps be good to mention this in the docs, here: 
>> https://pkg.go.dev/cmd/go#hdr-Build_constraints ?
>>
>> The bullet points refer to "unix" (which is true) and then a naïve 
>> reader, like me, would think the later paragraphs about GOOS also apply.
>>
>> Peter 
>>
>> On Thursday, 31 August 2023 at 10:13:12 UTC+1 Brian Candler wrote:
>>
>>> https://github.com/golang/go/issues/51572
>>>
>>> On Thursday, 31 August 2023 at 08:57:15 UTC+1 Peter Galbavy wrote:
>>>
>>>> I have used comment level build constraints for a while but I moved to 
>>>> using _linux.go and _windows.go over time as it makes it clearer for 
>>>> external viewing.
>>>>
>>>> A user reported they tried to build on MacOS and of course this didn't 
>>>> work. I renamed the _linux.go files to _unix.go suffixes but then when I 
>>>> do 
>>>> "GOOS=windows go build" those files were pulled in too. While I would say 
>>>> Windows is a POSIX-ish system I would contend it's not UNIX :-)
>>>>
>>>> I have gone and added "//go:build !windows" to all the renamed files 
>>>> for now, but is this intended behaviour?
>>>>
>>>> Peter
>>>>
>>>

-- 
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/a4c1bbc4-a777-4ce7-b389-949afd7a6a71n%40googlegroups.com.


[go-nuts] Re: go build of a *_unix.go file still used under windows ?

2023-08-31 Thread Peter Galbavy
Ah! Got it. Thanks.

Would it perhaps be good to mention this in the docs, 
here: https://pkg.go.dev/cmd/go#hdr-Build_constraints ?

The bullet points refer to "unix" (which is true) and then a naïve reader, 
like me, would think the later paragraphs about GOOS also apply.

Peter 

On Thursday, 31 August 2023 at 10:13:12 UTC+1 Brian Candler wrote:

> https://github.com/golang/go/issues/51572
>
> On Thursday, 31 August 2023 at 08:57:15 UTC+1 Peter Galbavy wrote:
>
>> I have used comment level build constraints for a while but I moved to 
>> using _linux.go and _windows.go over time as it makes it clearer for 
>> external viewing.
>>
>> A user reported they tried to build on MacOS and of course this didn't 
>> work. I renamed the _linux.go files to _unix.go suffixes but then when I do 
>> "GOOS=windows go build" those files were pulled in too. While I would say 
>> Windows is a POSIX-ish system I would contend it's not UNIX :-)
>>
>> I have gone and added "//go:build !windows" to all the renamed files for 
>> now, but is this intended behaviour?
>>
>> Peter
>>
>

-- 
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/f10bd61e-7a7a-46a0-b65f-ca9c62e8a9aan%40googlegroups.com.


[go-nuts] go build of a *_unix.go file still used under windows ?

2023-08-31 Thread Peter Galbavy
I have used comment level build constraints for a while but I moved to 
using _linux.go and _windows.go over time as it makes it clearer for 
external viewing.

A user reported they tried to build on MacOS and of course this didn't 
work. I renamed the _linux.go files to _unix.go suffixes but then when I do 
"GOOS=windows go build" those files were pulled in too. While I would say 
Windows is a POSIX-ish system I would contend it's not UNIX :-)

I have gone and added "//go:build !windows" to all the renamed files for 
now, but is this intended behaviour?

Peter

-- 
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/c3489aaa-185c-4532-8a07-54207e9f08b9n%40googlegroups.com.


[go-nuts] Re: Is there a good way to make binary files compiled on a high-version machine run on a low-version machine?

2023-08-11 Thread Peter Galbavy
I use a docker container with a centos7 image and build my shared libs 
there; 
https://github.com/ITRS-Group/cordial/blob/4f119f7893c67b817baaad23ed75b1ba134bf9c2/Dockerfile#L35

(pls don't judge my Dockerfile skills, it's a learning experience ;) )

On Thursday, 10 August 2023 at 11:12:23 UTC+1 fliter wrote:

> I have a project that uses CGO. After compiling on an ubuntu 20.04 
> compilation machine, it is distributed to other machines for execution, but 
> many of these machines have very low ubuntu versions, which may be ubuntu 
> 16.04 or ubuntu 18.04.
>
> In this way, when executing the binary file, an error similar to version 
> `GLIBC_2.29' not found will be reported.
>
> I try to use -a -ldflags '-extldflags "-static"' when go build. But it 
> seems that because of the use of cgo, it cannot be compiled successfully.
>
> Is there any good way, such as adding appropriate tags when go build, to 
> solve this problem?
>

-- 
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/0c9acea6-e6d0-4cd1-8045-c73604d63a48n%40googlegroups.com.


[go-nuts] Re: Can a struct be made comparable?

2023-07-14 Thread Peter Galbavy
As a slight digression - I thought I was going mad, but 'slices' and 'maps' 
are new :-) Only in 1.21 though...

Well, there is a lot of boiler plate that maps.Keys() will get rid of.

On Thursday, 13 July 2023 at 10:06:01 UTC+1 Brian Candler wrote:

> Structs are already comparable, but all fields must be the same:
> https://go.dev/play/p/XwhSz4DEDwL
>
> I think your solution with function 'eq' is fine.  You can see the same 
> thing in the standard library in slices.CompactFunc and slices.EqualFunc
> https://pkg.go.dev/slices#CompactFunc
> https://pkg.go.dev/slices#EqualFunc
>
> For the case of "ordered" rather than "comparable", have a look at 
> slices.BinarySearchFunc and related functions.
>
> On Thursday, 13 July 2023 at 09:29:38 UTC+1 Mark wrote:
>
>> I have a package which has a function `Do[T comparable](a, b []T) Result`.
>> I have a struct:
>> ```go
>> type N struct {
>>   x int
>>   y int
>>   t string
>> }
>> ```
>> Is it possible to make `N` comparable; in particular by a field of my 
>> choice, e.g., `t`?
>>
>> Or will I have to make, say, `DoFunc(a, b []N, eq func(i, j N) bool) 
>> Result` with, say,
>> `func eq(i, j N) { return i.t == j.t }`?
>>
>

-- 
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/2e40af3c-b032-4cc6-be67-36aaef1e8e71n%40googlegroups.com.


Re: [go-nuts] how to close a child process after father process be killed

2023-07-06 Thread Peter Galbavy
Yes, setsid combined with cmd.Process.Release() works for me.

My local / specific needs code 
is 
https://github.com/ITRS-Group/cordial/blob/ad18bfbfa44eff1b9b66408394dd83749da25bb1/pkg/process/process.go#L64
 
which works well for everything I have thrown at it (on Linux).

On Wednesday, 5 July 2023 at 16:23:16 UTC+1 Brian Candler wrote:

> > Is there any way to create a child process that is detached from the 
> original cgroup using exec.Command?
> > I don't want my child process to be killed when the parent process dies.
>
> This might be an issue with process groups, not cgroups, in which case I 
> think Setsid is what you want, something like (untested):
>
> p.theCommand.SysProcAttr = {Setsid: true}
> err := p.theCommand.Start()
>
> I had a related problem: I wanted to make sure that when a timeout occurs, 
> I forcibly kill the child process and all its descendants. Solution was to 
> use Setsid, and then send the signal to the newly-formed process group:
> https://groups.google.com/g/golang-nuts/c/V1VccYYCp9o/m/rZRfhP_bCAAJ
>
>

-- 
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/035a010a-7ed6-40ed-b800-aaad4caf1d82n%40googlegroups.com.


Re: [go-nuts] Export fs.FS as FUSE fs

2023-06-29 Thread Peter Galbavy
I can see a use - exporting an embedded FS (read only) from a binary, 
especially for testing stuff.

On Thursday, 29 June 2023 at 08:00:18 UTC+1 Roland Müller wrote:

> Hello,
> I am struggling to understand the purpose of extension. 
> FS is an interface to access file systems from go code. Is your new 
> extension acting as a handler and allows to expose any Go FS to be mounted 
> and acessed at operating system level?
>
>
> https://en.m.wikipedia.org/wiki/Filesystem_in_Userspace#/media/File%3AFUSE_structure.svg
>
> Br/Üdvözlettel
> Roland
>
> Am Samstag, 24. Juni 2023 schrieb Tamás Gulácsi :
> > Ok, I've put some hours into it, and implemented it: 
> https://pkg.go.dev/github.com/tgulacsi/g...@v0.25.0/fsfuse 
> 
> > It uses github.com/jacobsa/fuse to export a mountable io/fs.FS.
> > I've only tested with os.DirFS, with that, it works as expected.
> > I'd love to get some feedback - if anynone interested, I can export it 
> to some more direct/slimmer repo.
> > Tanás Gulácsi
> >
> > Tamás Gulácsi a következőt írta (2023. június 23., péntek, 8:08:32 
> UTC+2):
> >>
> >> Hi,
> >> Does anyone know an existing solution for exporting an fs.FS as a FUSE 
> filesystem?
> >> As fs.FS is standard now, this would open several new possibilities,
> >> as a lot of interesting fs.FS implementations exist (zip, tar, DB, 
> embedded, union ),
> >> and this one little glue code could export them all!
> >> Thanks in advance,
> >> Tamás
> >
> > --
> > 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/f8edf7e1-a864-4ab0-b7e6-773246485da1n%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/0bc4e33d-8d30-48fa-b1c2-a6a23cad5908n%40googlegroups.com.


[go-nuts] Re: regexp question

2023-02-10 Thread Peter Galbavy
FindAllStringSubmatch() 
? https://pkg.go.dev/regexp#Regexp.FindAllStringSubmatch

On Friday, 10 February 2023 at 12:52:34 UTC Jochen Voss wrote:

> Dear all,
>
> What happens if a group in a regular expression matches repeatedly, via 
> the * operator?  Experimentally I found that FindStringSubmatch then 
> returns the text of the last match.  Is this guaranteed somewhere (I didn't 
> find anything about this on https://pkg.go.dev/regexp )?  Also, is there 
> an easy way to get the other matched strings?
>
> Example: https://go.dev/play/p/h5UDongaz7u
>
> regexp: `A\s*(?:([a-z]+)\s*)*B`
> applied to: "one A two three four B five"
> the inner group gives me "four"
>
> Is FindStringSubmatch guaranteed to return the "four"? 
> Is there a way to also get the matched "two" and "three"?
>
> Many thanks,
> Jochen
>
>

-- 
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/9fd6b4b1-cb33-4a75-9bdf-54c25649fe19n%40googlegroups.com.


Re: [go-nuts] Re: Golang Github Package References

2022-12-05 Thread Peter Galbavy
Also, if you are concerned about the availability of the packages in the 
future, use vendoring to pull in a copy of the sources to the 
repo: https://go.dev/ref/mod#go-mod-vendor

Peter

On Monday, 5 December 2022 at 13:35:25 UTC Brian Candler wrote:

> On Monday, 5 December 2022 at 13:12:26 UTC loji...@gmail.com wrote:
>
>> The problem as I see it, is that when the security of the code relies on 
>> a package is outside the main program/executable, it can open potential 
>> problems of code injection; code changes or forks or if the url has moved, 
>> how these issues could cause the collapse of the integrity of the software. 
>>
>
> Go is a compiled language, and there are a few things you need to 
> understand about the compilation process.
>
> Firstly, there is no dynamic linking.  The *source code* for those 
> third-party libraries is fetched at compile time, and then compiled into 
> your binary, and that's it.  The binary is flat, containing your code and 
> the third-party code, all compiled together into a single blob.  The binary 
> does not change, and at runtime no new dependencies are pulled in or 
> updated; there is no route for code injection.
>
> Secondly, using go modules, in your source code you point to the *exact* 
> version of the third-party module that you want to import - either using 
> its version number, or a git commit reference. This is stored in 
> go.mod/go.sum.  The build of your application is reproducible.  If the 
> third-party module author releases a new or different version of their 
> module, then you have to explicitly pick it up - e.g. with "go mod tidy".
>
> Therefore, if someone else builds your code from source, version X, then 
> they will get exactly the same dependencies as you had when you released 
> version X.
>
> Thirdly, the imports are really module names, not urls.  Some of these 
> *happen* to look a bit like urls, and indeed there are mechanisms to fetch 
> the module source code automatically at compile time, if the module name 
> has the correct format.  But apart from that these are not used as urls, 
> and certainly not as urls embedded in the binary..
>
> Finally, if you are concerned about security problems, then you are right 
> to be aware of the versions of third-party libraries that you are using.  
> Of course, using newer versions of those libraries is likely to result in 
> fewer security holes, rather than more.  Therefore you need to track them, 
> and when they are updated, you'll want to recompile and re-release your own 
> software to take advantage of the fixes.
>
> HTH,
>
> Brian.
>

-- 
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/9c9b6f0d-a59d-445d-93e9-7d7dc1547c60n%40googlegroups.com.


[go-nuts] Re: Retrieve Path Parameters using inbuild http/Net package

2022-11-17 Thread Peter Galbavy
If you look in the http.Request passed to your handler, there is a URL 
field - use the net/url package to pull this out:

https://pkg.go.dev/net/url#URL

On Wednesday, 16 November 2022 at 09:08:38 UTC squadglad...@gmail.com wrote:

> Hello Everyone,
>
> I'm developing a http server using inbuilt http/net package in golang.
> Is there any way to get the path parameters from end points without using 
> any external third-party web framework?
>
> 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/acba5b94-0f4e-4034-ae48-c407675d411fn%40googlegroups.com.


Re: [go-nuts] Integration testing program that internally forks itself

2022-10-28 Thread Peter Galbavy
I also use a flag to do this, and I have a local package that then removes 
this flag (or any of a defined list) before re-execing the binary:

https://github.com/ITRS-Group/cordial/tree/main/pkg/process

https://pkg.go.dev/github.com/itrs-group/cordial/pkg/process#Daemon

It may not be perfect, but it works for my usage.

Peter

On Thursday, 27 October 2022 at 17:47:43 UTC+1 Jan Mercl wrote:

> Any recursion that does not have a terminating condition will try to 
> recurse infinitely ;-)
>
> I'm passing a command line flag in such situations - when testing, but the 
> best option depends on the particular use. Elsewhere, in a command that 
> starts a server or talks to the server, I used, for example, an ephemeral 
> @named socket, which nicely handled both the termination condition and the 
> communication and is even safe for concurrent processes competing with each 
> other.
>
> On Thu, Oct 27, 2022, 18:05 Vjeran  wrote:
>
>> We have a program that forks itself in order to do some work
>> so calling `./program do` internally finds its path using os.Executable 
>> and calls `./program do2`
>>
>> Now when trying to do integration tests program spawns itself and repeats 
>> test causing an infinite loop?
>>
>> Any ideas how to handle it? 
>>
>> -- 
>> 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/6f62afc4-af7a-4548-85c5-6514c2e20a49n%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/6756e27a-6e32-4374-8551-493f0ad89004n%40googlegroups.com.


Re: [go-nuts] go runtime in shared libs functions called in threads

2022-10-20 Thread Peter Galbavy
Thanks for the detail. We cannot change the calling program, just conform 
to it's API, so it's one function call per email send event and each in 
it's own (new) thread.

On Thursday, 20 October 2022 at 12:28:12 UTC+1 Konstantin Khomoutov wrote:

> On Wed, Oct 19, 2022 at 06:28:20AM -0700, Peter Galbavy wrote:
>
> > I have built a shared lib in Go to replace an old thing we use to send 
> > email - mainly to modernise things and add TLS and authentication. We 
> run 
> > each call to the entry point in it's own thread in the main program.
> > 
> > I am both curious but also concerned about what happens here with go 
> > runtimes. I presume each thread has it's own runtime, and on exit it is 
> > torn down, but I may be wrong and would like to know more.
>
> As already hinted, there's only a single instance of the Go runtime 
> powering
> your shared library after it got loaded and initialized. Basically it's the
> same thing as a regular Go program would call into a C library via cgo, and
> that library would be using multiple running threads which could access the
> data passed from the Go side and even call back to the Go side.
>
> To have less cognitive burden, I would recommend to move one step further 
> and
> make your library have a single entry point which would accept a job unit 
> and
> process it concurrently with any other job units - that is, defer 
> concurrency
> to the Go library.
>
> If you're basically already doing something like this and are only 
> concerned
> about what happens when you call to a Go library from multiple threads, 
> then
> the answer is - apply the usual logic: all variables which are local to the
> function call chain which got called from a thread are safe as they are not
> shared from the other call chains. If these call chains happen to share 
> some
> state in the library, you have to guared the access to it - in one way or
> another - using channels or resorting to mutexes etc.
>
>

-- 
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/d5f8e7f8-847a-4bbb-bc38-1d3c8ac05466n%40googlegroups.com.


[go-nuts] go runtime in shared libs functions called in threads

2022-10-19 Thread Peter Galbavy
I have built a shared lib in Go to replace an old thing we use to send 
email - mainly to modernise things and add TLS and authentication. We run 
each call to the entry point in it's own thread in the main program.

I am both curious but also concerned about what happens here with go 
runtimes. I presume each thread has it's own runtime, and on exit it is 
torn down, but I may be wrong and would like to know more.

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/444ba2f4-34eb-4105-b69a-646a7862f7ban%40googlegroups.com.


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

2022-10-01 Thread Peter Galbavy
We have a different requirement, which is opaquing of credentials in user 
visible config files. The company I work for has a basic way of doing this 
in the "real" product and I followed the same model for compatibility. 
There is, as yet, no auto rotation.

Basically, we generate an OpenSSL "compatible" key file and use that to 
encode and decode the credentials. The key file is still local but 
can/should be on a different file system and only readable by the app 
owner. The config files can then be edited / communicated with less chance 
of leaks. The objective is to protect against casual mistakes, not against 
determined actors.

I layered it, along with other local requirements, over viper so that 
"GetString" etc. just works.

https://github.com/ITRS-Group/cordial/tree/main/pkg/config

Peter


On Friday, 30 September 2022 at 17:34:29 UTC+1 Ivan Buljan wrote:

> Hello World
>
> This relates to that never ending question of securing the credentials in 
> production/staging envs, that is, avoiding storing them as plain text
>
> I am wondering if anyone could share their thoughts about the following 
> approach we are thinking of taking.
>
> Here we go:
>
> During build phase, an encryption key is generated and credentials are 
> encrypted with it.
>
> Once deployed, the instance decrypts credentials with the provided key and 
> does what it needs with them. Just before destroying the original files 
> (creds & key), the instance then generates a new encryption key and 
> re-encrypts a copy of credentials, which it keeps in memory. Newly 
> encrypted credentials along with the key are only dumped onto a filesystem 
> if the application panics and requires to be restarted, at which point the 
> same cycle key rotation decryption/encryption happens again.
>
> Is any security benefit with such approach?
>
>
>

-- 
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/d011891f-ab3f-41eb-8ad1-c90cbcf78a58n%40googlegroups.com.


[go-nuts] Re: Creating and Accessing DLL methods in GO

2022-09-29 Thread Peter Galbavy
Oh, hang on, please ignore my last message. It's that was because the 
*caller* was defined that way - it's NOT a Go thing. Oops, my bad.

Peter

On Thursday, 29 September 2022 at 10:33:23 UTC+1 Peter Galbavy wrote:

> On Linux at least - I have not tried building or using a Windows DLL, you 
> have to accept C-style args and process them in the exported function 
> signature:
>
> e.g.
>
> //export SendMail
> func SendMail(n C.int, args **C.char) C.int {
> conf := parseArgs(n, args)
> ...
>
> Here my parseArgs() func loops over the args and puts them in a map - 
> which is what I want, but your requirement will be different.
>
> Even if you are calling the function from Go code, I believe it still goes 
> through the C ABI. I just followed https://pkg.go.dev/cmd/cgo
>
> Peter
>
>
> On Thursday, 29 September 2022 at 09:58:02 UTC+1 squadglad...@gmail.com 
> wrote:
>
>> Hi Everyone,
>>
>> I'm trying to create go DLL for the below program using "go build 
>> -buildmode=c-shared -o calc.so calc.go"
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *package mainimport "C"func main() {}//export SayHellofunc SayHello(name 
>> string) {fmt.Printf("Go says: Hello, %s!\n", name)}//export Addfunc 
>> Add(num0, num1 int) int {return num0 + num1}*
>>
>> *-*
>> I have written the below logic to access DLL methods,
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *import "C"import (   "fmt"   "syscall"   "unsafe")var (   Library 
>>  syscall.Handle   IsInitialize = false   data = "World")func 
>> Loaddll() {   if Library == 0 {  var error_val error  
>> fmt.Printf("creating handle of c-share Wrapper\n")  Library, _ = 
>> syscall.LoadLibrary("calc.dll")  if error_val != nil {
>>  fmt.Println(fmt.Sprintf("Error occured while loading dll - %s", 
>> error_val.Error()))  }  getDetails()   }}func getDetails() {  
>>  key_uintptr := getUintPtrOfString(data)   helloMethod := 
>> getProc("SayHello")   get_secret_result, _, _ := 
>> syscall.SyscallN(uintptr(helloMethod), key_uintptr)   value := 
>> C.GoString((*C.char)(unsafe.Pointer(get_secret_result)))   if 
>> get_secret_result != 0 {  fmt.Println(fmt.Sprintf("Get code has given 
>> nonzero result\n %v", value))   }}func getProc(funcname string) (result 
>> uintptr) {   result, error_val := syscall.GetProcAddress(Library, 
>> funcname)   if error_val != nil {  fmt.Println(fmt.Sprintf("Error while 
>> getting proc %s", error_val.Error()))   }   return result}func 
>> getUintPtrOfString(s string) uintptr {   byte_s := append([]byte(s), 0)  
>>  return uintptr(unsafe.Pointer(_s[0]))}*
>>
>> **
>> I'm able to access the DLL method(Add) when we pass int as argument, but 
>> I'm getting errors while passing arguments as a string (Sayhello)..Here we 
>> are expecting the result as *Go says: Hello,*
>>
>

-- 
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/fa87406b-7de1-4aa5-a49d-27060cb9263bn%40googlegroups.com.


[go-nuts] Re: Creating and Accessing DLL methods in GO

2022-09-29 Thread Peter Galbavy
On Linux at least - I have not tried building or using a Windows DLL, you 
have to accept C-style args and process them in the exported function 
signature:

e.g.

//export SendMail
func SendMail(n C.int, args **C.char) C.int {
conf := parseArgs(n, args)
...

Here my parseArgs() func loops over the args and puts them in a map - which 
is what I want, but your requirement will be different.

Even if you are calling the function from Go code, I believe it still goes 
through the C ABI. I just followed https://pkg.go.dev/cmd/cgo

Peter


On Thursday, 29 September 2022 at 09:58:02 UTC+1 squadglad...@gmail.com 
wrote:

> Hi Everyone,
>
> I'm trying to create go DLL for the below program using "go build 
> -buildmode=c-shared -o calc.so calc.go"
>
>
>
>
>
>
>
>
>
>
>
> *package mainimport "C"func main() {}//export SayHellofunc SayHello(name 
> string) {fmt.Printf("Go says: Hello, %s!\n", name)}//export Addfunc 
> Add(num0, num1 int) int {return num0 + num1}*
>
> *-*
> I have written the below logic to access DLL methods,
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *import "C"import (   "fmt"   "syscall"   "unsafe")var (   Library 
>  syscall.Handle   IsInitialize = false   data = "World")func 
> Loaddll() {   if Library == 0 {  var error_val error  
> fmt.Printf("creating handle of c-share Wrapper\n")  Library, _ = 
> syscall.LoadLibrary("calc.dll")  if error_val != nil {
>  fmt.Println(fmt.Sprintf("Error occured while loading dll - %s", 
> error_val.Error()))  }  getDetails()   }}func getDetails() {  
>  key_uintptr := getUintPtrOfString(data)   helloMethod := 
> getProc("SayHello")   get_secret_result, _, _ := 
> syscall.SyscallN(uintptr(helloMethod), key_uintptr)   value := 
> C.GoString((*C.char)(unsafe.Pointer(get_secret_result)))   if 
> get_secret_result != 0 {  fmt.Println(fmt.Sprintf("Get code has given 
> nonzero result\n %v", value))   }}func getProc(funcname string) (result 
> uintptr) {   result, error_val := syscall.GetProcAddress(Library, 
> funcname)   if error_val != nil {  fmt.Println(fmt.Sprintf("Error while 
> getting proc %s", error_val.Error()))   }   return result}func 
> getUintPtrOfString(s string) uintptr {   byte_s := append([]byte(s), 0)  
>  return uintptr(unsafe.Pointer(_s[0]))}*
>
> **
> I'm able to access the DLL method(Add) when we pass int as argument, but 
> I'm getting errors while passing arguments as a string (Sayhello)..Here we 
> are expecting the result as *Go says: Hello,*
>

-- 
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/8b6ccd4c-3287-4a78-a305-274e1c12e0ben%40googlegroups.com.


[go-nuts] Re: Single Job to Multi Job

2022-09-20 Thread Peter Galbavy
A good starting point is to look for a multiplxer / multiplexor

On Saturday, 17 September 2022 at 11:59:11 UTC+1 ramki...@hotmail.com wrote:

> I have a tcp server that collects jobs (lets say 10), and tcp clients get 
> the jobs. This is done in a FIFO method, where the first job the server 
> gets, all tcp clients get that job. When that job is completed, all tcp 
> clients get the second job etc etc.
>
> I'm trying to find a way/term (so that I can google template code) on how 
> to convert this FIFO method to one where it sends (let's say) job 1, 2 and 
> 3 to three different clients, so that they work on it in parallel.
>

-- 
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/2bc9b736-2ea6-4f9f-bf7a-35a5fe028a8an%40googlegroups.com.


Re: [go-nuts] How to run a java file using go script.

2022-08-04 Thread Peter Galbavy
When you use

  cmd, err := exec.Command(...)

you then set-up it's environment before execution by setting cmd.Env:

  cmd.Env = append(os.Environ(), `PATH="..."`)

and only then run the command:

  out, err := cmd.Output()
  if err ... { ... }
  fmt.Println("output:", out)

The above mostly from memory, so excuse syntax.

On Thursday, 4 August 2022 at 07:11:57 UTC+1 Jan Mercl wrote:

> On Thu, Aug 4, 2022 at 6:24 AM TECHAX  wrote:
>
> > I tried the following one but still, it's not working.
> >
> > os.Setenv("PATH","/home/sdk/jdk-11.0.16/bin")
> > cmd,_:=exec.Command("java","-version").Output()
> > fmt.Println(string(cmd))
> >
> > Since the path is set, so it should display the java version, right?
>
> Check and share the value of error returned by Command.Output(). Also,
> try CombinedOutput() instead of Output().
>

-- 
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/552fdb00-ce1c-4441-9609-fa962cb6000en%40googlegroups.com.


[go-nuts] Re: ListenAndServeTLS() (pem and key files for private network)

2022-06-28 Thread Peter Galbavy
If it helps, I put this together for my own project - it's not a package 
but a bunch of convenience functions/methods for generating TLS certs and 
keys (there is a lot of implementation specific stuff), but the general 
shape may help you:

https://github.com/itrs-group/cordial/blob/main/tools/geneos/internal/instance/tls.go

Peter

On Tuesday, 28 June 2022 at 01:35:38 UTC+1 hugh@gmail.com wrote:

> I wish to create a secure private network using a self-signed certificate 
> with a Go web server: See the following code block:
>
> // Code 
> err := http.ListenAndServeTLS(":"+port, "auto.org.pem", 
> "auto.org-key.pem", handler)
> if err != nil {
>
> logError((err.Error()))
> log.Fatal("ListenAndServe: ", err)
> }
> // End of Code
>
> Could I auto  generate (and register) the .pem and .key files using GO?  I 
> wish to create a trust certificate if there files do not exist.
>
> I came across the following website:
>
> "https://gist.github.com/shaneutt/5e1995295cff6721c89a71d13a71c251;
>
> I am not sure how to implement this. Your help is appreciated.
>

-- 
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/2c4a6aee-0b1f-454b-a725-c4233759ed27n%40googlegroups.com.


Re: [go-nuts] passing a string slice to a variadic function expecting []interface{} or []any

2022-06-22 Thread Peter Galbavy
Thanks for setting my mind at ease.

On Wednesday, 22 June 2022 at 16:05:17 UTC+1 axel.wa...@googlemail.com 
wrote:

> No, there is no way to do it. You have to make a copy of the slice as you 
> did.
>
> On Wed, Jun 22, 2022 at 4:58 PM Peter Galbavy  
> wrote:
>
>> This is probably an FAQ but...
>>
>> I've tried to understand this before but gave up; I am trying to (quick 
>> and dirty) import from a CSV or Excel file to a DB and I would like to take 
>> the slice from csv.Read() and just pass it through to stmt.Exec() but 
>> because the first is a []string and the second a []interface{} or []any (in 
>> 1.18+) it baulks. e.g.
>>
>>   fields, err := csv.Read()
>>   ... checks
>>   _, err = stmt.Exec(fields)
>>
>> I got round it by looping over the slice and putting appending the 
>> strings to a []interface{} local.
>>
>> Is there a simpler way to do this inline - please ignore the issues 
>> around the contents or the number of elements for now.
>>
>> -- 
>> 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/3c20e19d-8805-4f76-b52b-a3b8275ea708n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/3c20e19d-8805-4f76-b52b-a3b8275ea708n%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/d6c39bd9-8f50-4b0e-84e3-71c96f726107n%40googlegroups.com.


[go-nuts] passing a string slice to a variadic function expecting []interface{} or []any

2022-06-22 Thread Peter Galbavy
This is probably an FAQ but...

I've tried to understand this before but gave up; I am trying to (quick and 
dirty) import from a CSV or Excel file to a DB and I would like to take the 
slice from csv.Read() and just pass it through to stmt.Exec() but because 
the first is a []string and the second a []interface{} or []any (in 1.18+) 
it baulks. e.g.

  fields, err := csv.Read()
  ... checks
  _, err = stmt.Exec(fields)

I got round it by looping over the slice and putting appending the strings 
to a []interface{} local.

Is there a simpler way to do this inline - please ignore the issues around 
the contents or the number of elements for now.

-- 
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/3c20e19d-8805-4f76-b52b-a3b8275ea708n%40googlegroups.com.


[go-nuts] Re: Installing a package with an associated command

2022-05-25 Thread Peter Galbavy
It's worth noting that @latest only works for "releases" and not for 
tags/releases labelled pre-release. Just in case anyone hits the same issue 
I did a while back! :)

On Wednesday, 25 May 2022 at 07:40:04 UTC+1 Volker Dobler wrote:

> If you want the command to be installed: Why don't you install
> _the_ _command_ with 
> go install https://github.com/chmike/clog/cmd/clogClr@latest
> ? (Note that there is no need to install the package.)
>
> V.
>
> On Wednesday, 25 May 2022 at 08:13:58 UTC+2 christoph...@gmail.com wrote:
>
>> I have a small package (https://github.com/chmike/clog) that also 
>> contains a command in the cmd subdirectory (clogClr). How do I install 
>> the clog package and the command ? 
>>
>> When I execute "go install github.com/chmike/clog@latest" I get the 
>> error message that it is not a main package. When I use go get that package 
>> is installed, but not the command (clogClr). 
>>
>> I understand that for security purpose installing a package should not 
>> automatically install an executable binary. 
>>
>> For now I do a git clone and a "go install ./...". It's fine for me, not 
>> for an end user. I assume there is a better 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/248b767d-d4d2-473a-a685-35c41eab6bfan%40googlegroups.com.


[go-nuts] Re: Blog: Calculating type sets is harder than you think

2022-05-17 Thread Peter Galbavy
I am neither enough of a Go expert ("yet) - I hope) or good enough in real 
math to say much apart from that is actually one of the clearest 
explanations of P/NP problems and the actual meaning of CNF/DNF that I have 
had the pleasure to read. Even setting aside the importance to the design 
decisions for Go 1.18, it actually made sense of things I have struggled in 
the past to "get".\

Thanks.

On Monday, 16 May 2022 at 11:24:22 UTC+1 axel.wa...@googlemail.com wrote:

> Hi,
>
> I thought you might be interested in a new blog post I just published, 
> about the difficulties of proving that a type set is empty:
> https://blog.merovius.de/posts/2022-05-16-calculating-type-sets/
> It is based on a problem that came up when the notion of type sets was 
> proposed 
> . It 
> came up a couple of times lately in discussions about changing the generics 
> design, so I thought it might be good to do a clean writeup.
>
> Let me know what you think. 
>

-- 
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/a2dd523a-56c4-4bfb-99e2-7245a708a578n%40googlegroups.com.


[go-nuts] Re: Which is the most efficient way to read STDIN lines 100s of MB long and tens of MB info is passed to it?

2022-05-08 Thread Peter Galbavy
Rather than overthink it at this stage, just use bufio.Scanner and 
strings.Contains() and see what performance is like. I suspect that for a 
plain string and a large-ish file it will be about as good as it gets.


On Sunday, 8 May 2022 at 09:36:15 UTC+1 Tamás Gulácsi wrote:

> If that "100s of MB" is acceptable to be in memory, then bufio.Scanner 
> with properly sized scanner.Buffer is the easiest and battle tested 
> solution.
>
> If not, then you have to reimplement the same, with a temp file as a 
> buffer: read input, store in file, seeking to the start on each '\n', 
> copying the file to STDOUT when "test" is found.
> Not too hard, but have a few edge cases.
> Const V a következőt írta (2022. május 7., szombat, 22:40:58 UTC+2):
>
>> I need to write a program that reads STDIN and should output every line 
>> that contains a search word "test" to STDOUT. 
>>
>> How I can test that considering the problem is a line can be 100s of MB 
>> long (\n is line end) and tens of MB info is passed to it.
>>
>

-- 
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/7497c428-810e-4aad-8c34-86b59134f009n%40googlegroups.com.