Re: [go-nuts] What's go's convention for specifying the equivolent of configure --prefix?

2022-12-01 Thread hey...@gmail.com
@Nick @Brian Somehow I missed your replies. Using a Makefile makes sense. And thanks for bringing embed to my attention. I never knew it exists. Sounds like it can solve my problem. Thanks a lot. On Thursday, December 1, 2022 at 6:32:58 PM UTC+8 Nick wrote: > On Thu, Dec 01, 2022 at 06:21:37P

Re: [go-nuts] What's go's convention for specifying the equivolent of configure --prefix?

2022-12-01 Thread Glen Huang
@m.shulhan @hervinhioslash Thanks for the suggestion. I agree that using a runtime mechanism like env vars or command line flag can solve this problem. But the path value is for internal use, it should be customized only by the system administrators or package managers who determine where to in

Re: [go-nuts] vendors and modules

2022-12-01 Thread Ian Lance Taylor
On Thu, Dec 1, 2022 at 3:23 PM Andrew Athan wrote: > > I am new to go devops (but not to the language). First, I must say, the go > module documentation is thorough but absolutely inscrutable for new users. > Googling for things like "golang add github module vendor" brings up what > appear to

[go-nuts] vendors and modules

2022-12-01 Thread Andrew Athan
I am new to go devops (but not to the language). First, I must say, the go module documentation is thorough but absolutely inscrutable for new users. Googling for things like "golang add github module vendor" brings up what appear to be either outdated or incorrect cookbooks. I've already wasted

[go-nuts] Re: How can I use go with Modules

2022-12-01 Thread Jason Bramsden
I'm going to answer my own question as I've managed to figure it out. Set the following environment variable: GO111MODULE=off When I previously looked at the environment variables using go env the GO111MODULE="", which I thought was off. But if this environment variable is not set then it is as

[go-nuts] Re: What's go's convention for specifying the equivolent of configure --prefix?

2022-12-01 Thread Brian Candler
If you are happy for the compile-time data to be in a file, rather than supplied as flags to the build command, then //go:embed should do the trick. https://pkg.go.dev/embed On Thursday, 1 December 2022 at 09:39:38 UTC hey...@gmail.com wrote: > I'm writing a command line program in go, and it n

[go-nuts] How can I use go with Modules

2022-12-01 Thread Jason Bramsden
BLUF: Is there any way to use the latest version of Go without Modules? Some flag or environment setting where I can disable it? I've been developing on Go since 2011, and I find Modules so frustrating! Life was so much easier without Modules, I could download packages from a git repo using go

[go-nuts] Why variable escapes?

2022-12-01 Thread Stepan Chelyshev
Why does x3 escape? Is it even correct considering s3 and x3 gets destroyed in the same moment (when function main ends)? Why x1 and x2 do not escape? *Code:* package main func main() { // 1 case, doesn't escape, struct field is pointer type S1 struct { val *int } var

Re: [go-nuts] What's go's convention for specifying the equivolent of configure --prefix?

2022-12-01 Thread Kyle
I'd use godotenv in this case. True, it will require a .env file with a path variable in it and true it won't be as having consts but it will do the job. import ( "os" "github.com/joho/godotenv" ) func init() { if os.Getenv("MODE") != "PROD" { godotenv.Load() } } // ... // The

[go-nuts] Re: Looking Backend Dev Learning Resources

2022-12-01 Thread Marcello H
https://mehdihadeli.github.io/awesome-go-education/ Op woensdag 30 november 2022 om 14:12:46 UTC+1 schreef christoph...@gmail.com: > If you know the basics of Go already, Effective Go > and the Go FAQ are > good starting points for lear

Re: [go-nuts] How to fix an awful marshal reflection hack

2022-12-01 Thread burak serdar
On Thu, Dec 1, 2022 at 6:39 AM 'Mark' via golang-nuts < golang-nuts@googlegroups.com> wrote: > The reason there's no nullable in the real code is that it isn't needed > there: if the field is to a pointer variable (e.g., *string), then I call > hack() and that adds the '?' to the string so no need

Re: [go-nuts] How to fix an awful marshal reflection hack

2022-12-01 Thread 'Mark' via golang-nuts
The reason there's no nullable in the real code is that it isn't needed there: if the field is to a pointer variable (e.g., *string), then I call hack() and that adds the '?' to the string so no need for a nullable bool; otherwise for non-pointers it falls through to the normal processing. So t

Re: [go-nuts] How to fix an awful marshal reflection hack

2022-12-01 Thread Marvin Renich
* 'Mark' via golang-nuts [221201 05:17]: > I tried that and it works in the playground, and I added more types and it > still works in the playground . > But in my program it still doesn't work:-( > The actual code is here tdb-go

[go-nuts] net/netip and UDP servers

2022-12-01 Thread Juliusz Chroboczek
I'm writing a simple UDP server, and I'm trying to use the new net/netip data types. My main loop starts as follows: for { n, a, err := sock.ReadFrom(buf) if err != nil { log.Printf("ReadFrom: %v", err) time.Sleep(100 * time.Millisecond) con

Re: [go-nuts] What's go's convention for specifying the equivolent of configure --prefix?

2022-12-01 Thread Shulhan
On Thu, 1 Dec 2022 18:21:37 +0800 Glen Huang wrote: > > Whats wrong with const? > > Const is the ideal choice, but how do users of my program specify the > path when they compile it? > They can't, but in Go, I am leaning to prefer where user can set the "prefix" when running the program rathe

[go-nuts] [ANN] new linter for "mixed pointer and value receivers"

2022-12-01 Thread Nikolay Dubina
*what?* New go vet compatible linter that detects mixing pointer and value method receivers for the same type. https://github.com/nikolaydubina/smrcptr *why?* It is recommended in Go wiki and in Google Go style guide. It is very common principle to keep code clean in practice and code reviews

Re: [go-nuts] What's go's convention for specifying the equivolent of configure --prefix?

2022-12-01 Thread Nick
On Thu, Dec 01, 2022 at 06:21:37PM +0800, Glen Huang wrote: > Const is the ideal choice, but how do users of my program specify the path > when > they compile it? I don't think this is something for which there is a "canonical Go way", so I'd say something like a tiny makefile that sets the path

Re: [go-nuts] What's go's convention for specifying the equivolent of configure --prefix?

2022-12-01 Thread Glen Huang
> Whats wrong with const? Const is the ideal choice, but how do users of my program specify the path when they compile it? > And could not be global var then? Using var loses the guarantee that the path won’t be changed, and the go compiler can no longer optimize as much I presume? -- You

Re: [go-nuts] How to fix an awful marshal reflection hack

2022-12-01 Thread 'Mark' via golang-nuts
I tried that and it works in the playground, and I added more types and it still works in the playground . But in my program it still doesn't work:-( The actual code is here tdb-go in the file marshal.go from line 13

Re: [go-nuts] What's go's convention for specifying the equivolent of configure --prefix?

2022-12-01 Thread Shulhan
On Thu, 1 Dec 2022 01:39:38 -0800 (PST) "hey...@gmail.com" wrote: > I'm writing a command line program in go, and it needs to access some > predefined external files like /usr/lib/name/file. What would be a > good way to allow specify the constant path in compile time? > > I see two options: >

Re: [go-nuts] How to fix an awful marshal reflection hack

2022-12-01 Thread 'Dan Kortschak' via golang-nuts
On Thu, 2022-12-01 at 00:33 -0800, 'Mark' via golang-nuts wrote: > Thanks. I've now tried that as follows: > >         fmt.Printf("@@: %T %v\n", field, field) >         kind = field.Type().Elem().Kind() >         fmt.Printf("##: %T %v\n", field, field) > > In every case the output for kind

[go-nuts] What's go's convention for specifying the equivolent of configure --prefix?

2022-12-01 Thread hey...@gmail.com
I'm writing a command line program in go, and it needs to access some predefined external files like /usr/lib/name/file. What would be a good way to allow specify the constant path in compile time? I see two options: 1. go generate 2. -ldflags="-X 'main.Path=..." Both seem to be flawed. For #1

Re: [go-nuts] How to fix an awful marshal reflection hack

2022-12-01 Thread 'Mark' via golang-nuts
Thanks. I've now tried that as follows: fmt.Printf("@@: %T %v\n", field, field) kind = field.Type().Elem().Kind() fmt.Printf("##: %T %v\n", field, field) In every case the output for kind before and after was identical. (Naturally, I tried without the print statem