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

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] Possible to make go not touch the built file if it builds purely from cache?

2020-04-15 Thread Glen Huang
Thanks, as mentioned in the previous reply, this is what I end up using. On Thursday, April 16, 2020 at 10:25:03 AM UTC+8, Shulhan wrote: > > > > On 15 Apr 2020, at 18.55, Glen Huang > > wrote: > > > > I have a makefile where upon a new go binary being built,

Re: [go-nuts] Possible to make go not touch the built file if it builds purely from cache?

2020-04-15 Thread Glen Huang
e go build directly. move-if-change sounds like a good approach, will come in handy when there is no need to cross compile, thanks for the tip. On Thursday, April 16, 2020 at 4:09:27 AM UTC+8, Ian Lance Taylor wrote: > > On Wed, Apr 15, 2020 at 4:55 AM Glen Huang > > wrote: > > >

[go-nuts] Possible to make go not touch the built file if it builds purely from cache?

2020-04-15 Thread Glen Huang
I have a makefile where upon a new go binary being built, it builds some other stuff that is not go related. The go binary is unconditionally built with a FORCE prerequisite, so the go build command always runs, but that command always updates the output binary, which leads to downstream being

Re: [go-nuts] Any reason why this type conversion is not allowed?

2020-04-14 Thread Glen Huang
@lan @Shulhan Thanks. Glad to know the design goal much better. On Tuesday, April 14, 2020 at 1:07:36 PM UTC+8, Ian Lance Taylor wrote: > > On Mon, Apr 13, 2020 at 6:56 PM Glen Huang > > wrote: > > > > Given > > > > type Data []byte > > s :

Re: [go-nuts] Any reason why this type conversion is not allowed?

2020-04-13 Thread Glen Huang
on of this type, since one structure isn't > safely coercible to the other type. This would be along the lines of > reinterpret_cast<> in c++, which can corrupt memory. > > > On Mon, Apr 13, 2020 at 6:56 PM Glen Huang > > wrote: > >> Given >>

[go-nuts] Any reason why this type conversion is not allowed?

2020-04-13 Thread Glen Huang
Given type Data []byte s := [][]byte{{1},{2}} I wonder why this conversion isn't allowed? []Data(s) Seems pretty straightforward. Maybe I miss some edge cases where things won't square? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To

Re: [go-nuts] Re: Directly assign map[string]int to map[string]interface{}?

2020-02-23 Thread Glen Huang
ible. > > On Sun, Feb 23, 2020 at 10:24 AM Glen Huang > wrote: > >> Another slightly related topic: >> >> switch v := i.(type) { >> case map[string]interface{}, map[string]int: >> fmt.Print(v) >> } >> >> Ideally v is of type map[strin

[go-nuts] Re: Directly assign map[string]int to map[string]interface{}?

2020-02-23 Thread Glen Huang
Another slightly related topic: switch v := i.(type) { case map[string]interface{}, map[string]int: fmt.Print(v) } Ideally v is of type map[string]interface{}, but it's interface{} instead. On Sunday, February 23, 2020 at 5:12:27 PM UTC+8, Glen Huang wrote: > > Hi, > > I hav

[go-nuts] Directly assign map[string]int to map[string]interface{}?

2020-02-23 Thread Glen Huang
Hi, I have a function that accepts an argument of type map[string]interface{}, and I also have a value of type map[string]int. Currently it seems I can't directly pass the value to the function. Is there anyway I can directly coerce it or a new value of the exact matching type must be

[go-nuts] Re: How to correctly json.Unmarshal struct whose embedded structs define UnmarshalJSON

2020-01-01 Thread Glen Huang
you "inherit" these methods and you don't want this to happe Given the case above, I'm wondering if embedding + not overriding method is possible? On Thursday, January 2, 2020 at 9:19:23 AM UTC+8, Ben Bullock wrote: > > > > On Tuesday, 31 December 2019 19:21:07 UTC+9, Glen

[go-nuts] Re: How to correctly json.Unmarshal struct whose embedded structs define UnmarshalJSON

2019-12-31 Thread Glen Huang
After thinking more about it, I start to feel that maybe using embedded structs is generally a bad idea with dealing with json? Is the correct solution here to use explicit fields? BTW, happy New Year everyone. On Tuesday, December 31, 2019 at 6:21:07 PM UTC+8, Glen Huang wrote: > >

[go-nuts] How to correctly json.Unmarshal struct whose embedded structs define UnmarshalJSON

2019-12-31 Thread Glen Huang
I want to unmarshal a struct that contains embedded structs: type Parent struct { Child P int } type Child struct { Grandchild C int } type Grandchild struct { G int } The problem is that Grandchild defines its own UnmarshalJSON method, and that means Parent inherits it and breaks

Re: [go-nuts] Question regarding gob

2019-03-25 Thread Glen Huang
on hiatus) right now? On Monday, March 25, 2019 at 10:36:12 PM UTC+8, Sameer Ajmani wrote: > > With gRPC, I recommend you use protobuf. > > On Mon, Mar 25, 2019 at 8:18 AM Glen Huang > > wrote: > >> I planed to use net/rpc with gob, but then found the GitHub issue sayin

[go-nuts] Question regarding gob

2019-03-25 Thread Glen Huang
I planed to use net/rpc with gob, but then found the GitHub issue saying net/rpc is deprecated, and people should be using grpc instead. That leads to the question should I use grpc with gob or stick with protobuf? Google suggests not many people talk about using grpc with gob, any there

Re: [go-nuts] How to limit client IPs in tls listener?

2019-03-15 Thread Glen Huang
So looks like nftables is my only choice then? On Friday, March 15, 2019 at 10:30:28 PM UTC+8, Andrei Tudor Călin wrote: > > That sounds like something a firewall would do, not your Go program. > > On 3/15/19 3:14 PM, Glen Huang wrote: > > Thanks, but if I'm not wrong, that m

Re: [go-nuts] How to limit client IPs in tls listener?

2019-03-15 Thread Glen Huang
> > Then, to use: > > ln, err := net.Listen("tcp", addr) > if err != nil { > log.Fatal(err) > } > aln := {allowed: yourListOfIPs, inner: ln} > tlsln := tls.NewListener(aln, yourTLSConfig) > > // use tlsln > > On 3/15/19 2:58 PM,

Re: [go-nuts] How to limit client IPs in tls listener?

2019-03-15 Thread Glen Huang
checks the list of allowed > IPs. > You'll be able to run code before the connection is passed on to > crypto/tls. > Wrap it using https://golang.org/pkg/crypto/tls/#NewListener. > > On 3/15/19 2:10 PM, Glen Huang wrote: > > I'm trying to limit which clients are allowed

[go-nuts] How to limit client IPs in tls listener?

2019-03-15 Thread Glen Huang
I'm trying to limit which clients are allowed to connect to my tls server by their IPs. I know I can do that after Accept, check their IPs and close the connection if they're not whitelisted. But that means the full tls handshake has to complete before I can do that. Another option is that I

Re: [go-nuts] Doc mentioned it's possible to inspect unexported methods using reflect, but I can't figure out how

2018-01-20 Thread Glen Huang
Thanks for the reply. Hopefully the doc can be changed to avoid confusion. On Sunday, January 21, 2018 at 1:16:04 PM UTC+8, Ian Lance Taylor wrote: > > On Sat, Jan 20, 2018 at 8:43 PM, Glen Huang <hey...@gmail.com > > wrote: > > > > The doc for the method

[go-nuts] Doc mentioned it's possible to inspect unexported methods using reflect, but I can't figure out how

2018-01-20 Thread Glen Huang
Hi, The doc for the method type in the reflect package (https://golang.org/pkg/reflect/#Method) seems to suggest that it's possible to inspect a type's unexported methods: // PkgPath is the package path that qualifies a lower case (unexported) // method name. It is empty for

[go-nuts] Re: How to mock things without having too big an impact on the source code?

2017-11-15 Thread Glen Huang
ervice > } > > > func(h handleLogin)ServeHTTP(w http.ResponseWriter,r *http.Request){ > h.Service.CallThis(r) > } > > You can only write unit tests if you write testable code at first place. > > Le mercredi 15 novembre 2017 03:28:28 UTC+1, Glen Huang a écrit : >> &g

[go-nuts] How to mock things without having too big an impact on the source code?

2017-11-14 Thread Glen Huang
I find that to be able to unit test things in golang, I need to restructure them in an uncomfortable way in order to be able to mock their dependencies. For example, say I want to test this simple http handler: func handleLogIn(w http.ResponseWriter, r *http.Request) { svc :=

[go-nuts] Re: Problem designing APIs after the compress stdlib

2017-11-09 Thread Glen Huang
Any suggestion how to improve compressor and resizer's APIs? Regards, Glen On Thursday, November 9, 2017 at 12:26:14 PM UTC+8, Glen Huang wrote: > > I'm writing a small image processing tool, given an image content, it only > does two things: > > 1. compressing the image content

[go-nuts] Problem designing APIs after the compress stdlib

2017-11-08 Thread Glen Huang
I'm writing a small image processing tool, given an image content, it only does two things: 1. compressing the image content 2. generating a thumbnail (by resizing and then compressing it) I want to model the compressing(the same goes for resizing) after the compress stdlib: you create a

Re: [go-nuts] How to check if a request was cancelled

2017-11-08 Thread Glen Huang
ave succeeded, or failed for another reason, before the > context was cancelled. Whether this matters is of course up to the > application. > > //jb > > >> On 8 Nov 2017, at 13:19, Jan Mercl <0xj...@gmail.com >> <mailto:0xj...@gmail.com>> wrote: >&

Re: [go-nuts] Re: How to check if a request was cancelled

2017-11-08 Thread Glen Huang
> switch; > > _, err := http.DefaultClient.Do(r) > if urlErr, ok := err.(*url.Error); ok { > log.Println(urlErr.Err == context.Canceled) // “true", in your example > } > > //jb > > > On 8 Nov 2017, at 13:11, Glen Huang <hey...@gmail.com > > wrote: > >

[go-nuts] Re: How to check if a request was cancelled

2017-11-08 Thread Glen Huang
mber 2017 14:02.13 UTC+2 kirjutas Glen Huang: >> >> I have this simple code in which I try to check if the request was >> cancelled. But surprisingly, it prints false instead of true in go 1.9. >> >> I wonder what's the correct way to check that? >> >> pa

Re: [go-nuts] Correct way to track each individual goroutine

2017-07-25 Thread Glen Huang
Jul 25, 2017 at 6:56 AM Glen Huang <hey...@gmail.com > > wrote: > >> >> My current design is that uploading is finished as soon as the image is >> uploaded to the server, after which I spawn a goroutine to exec a command >> to do the compression. Wh

[go-nuts] Re: Correct way to track each individual goroutine

2017-07-25 Thread Glen Huang
oh, never thought about that. Initially there will be only server but it's only matter of time I need to scale to multiple servers. I'll probably give redis a shot. Thanks for the suggestion! On Wednesday, July 26, 2017 at 8:33:59 AM UTC+8, Florin Pățan wrote: > > Will the user always end up

[go-nuts] Re: Correct way to track each individual goroutine

2017-07-25 Thread Glen Huang
Thanks for bringing singleflight to my attention. However, if I'm not wrong, it doesn't seem to fully solve the problem. If after uploading, I call singleflight.Do, and pass the file name and the compression function, when users requests a file, should I call singleflight.Do and pass the

[go-nuts] Re: How to determine when to actually use goroutines?

2017-07-24 Thread Glen Huang
lable > by searching for those keywords. > > On Tuesday, 25 July 2017 01:34:30 UTC+10, Glen Huang wrote: >> >> Hi, >> >> I'm still pretty new to go. Hope this question isn't too stupid. >> >> I'm writing a restful API server, and in order to send a respon

[go-nuts] Re: How to determine when to actually use goroutines?

2017-07-24 Thread Glen Huang
ill cause issues, and even if they do, solutions > such as adding indexes to problematic fields or doing caching might help A > LOT more than trying to be more concurrent will. > > > On Monday, July 24, 2017 at 8:34:30 AM UTC-7, Glen Huang wrote: >> >> Hi, >> >&g

[go-nuts] How to determine when to actually use goroutines?

2017-07-24 Thread Glen Huang
Hi, I'm still pretty new to go. Hope this question isn't too stupid. I'm writing a restful API server, and in order to send a response, I need to query a db to get its content type and then send the actually file that lives on the file system. Now the question is, should I put db.QueryRow and