Re: [go-nuts] [RFC] Yet another proposal for Go2 error handling
Hi Mike, On Thu, 29 Jun 2023 22:04:01 -0700 (PDT) Mike Schinkel wrote: > There are many aspects of this proposal that I really like, and a few > that I think need to be reconsidered. > > In general I like that it: > >1. Does not try to handle errors *above *where the errors > occurred, which is the pattern when using both *defer* and > *recover(). *I personally find having to jump back much harder to > reason about than jumping forward to find the error handler. >2. Does not require handling the error in a closure or other > *func* as the former adds a lot of visual noise and the latter > complicates by creating a different variable scope. > > > It is in many ways similar to a proposal I have been planning on > preparing but have no found the right opportunity. Possibly this is > the right opportunity and maybe taking aspects of this and aspects of > mine we could find a solution beneficial enough that Ian Lance Taylor > would consider it a big enough improvement. I'll try to follow up on > that soon. > > As for the specifics of this proposal: > > 1. I think *when err handle * is a bit too much magic. I > think it would be more Go-like if it were instead: > >*when err!=nil handle * > > I know this makes for more repeated syntax, but within the scope of > this proposal I do not think you can avoid it without it adding > magic. I do think that could be addressed, and what I have in mind > addresses that. But I wanted to first comment on your proposal, not > introduce mine. If we use WHEN like this, then there is no different with IF statement. The purpose of WHEN statement is to check for non-zero value. Using IF statement, it could be written like these if !ZeroValue(err) handle > > 2. As for *check* as you have proposed it — handling zero return > values — it seems to add more magic, and that it would only work in > selected use-cases so it might be best to omit this from the proposal? I am not sure on this one. The "check" keywords is proposed by parent proposal [1], not by this proposal. [1] https://go.googlesource.com/proposal/+/master/design/go2draft-error-handling-overview.md > > 3. I do like the concept of labels that do not fall through to the > code in the next label. However, it is not exactly clear how they > should work. Do your handlers always have to have a *return* > themselves? > > > *func foo()error {* > * ...* > * when err != nil handle cleanup* > * ...* > * return nil* > >:*cleanup:* > *doCleanup()* > * return err* >*}* No. The body of handler is similar with body of function. If the function does not expect return value than the execution of function body will stop before the first handler defined. Case example, func main() { hex, err := ioutil.ReadAll(os.Stdin) when err handle fatal data, err := parseHexdump(string(hex)) when err handle fatal os.Stdout.Write(data) // The function body stop here, the log.Fatal below will not be // executed. :fatal: log.Fatal(err) } > > 4. When you are in a handler, is there any way to correct the problem > and *resume* or *retry* the code where you left off without resorting > to using *goto* and labels? No, but one can use by using recursive call. IMO, the part of code that try handling error by resuming or retry is an indication that it should be moved into separate function. > > 5. I do not think you need the new keyword *handle*, i.e. I think > this would be sufficient to use *goto* instead since the syntax of > your handler label with the preceding colon should be sufficient to > distinguish between the two: > > > *when err!=nil goto * That is possible, yes, I think it will minimise number of new syntax introduced by this proposal. I believe the implementation in the Go internal would be rather complex. > 6. If you use *goto* instead of *handle* then you actually have two > orthogonal features, the latter one being labels that do not fall > through that can be used without when. Those could be proposed as a > feature in their own right. > > 7. How would your proposal handle shared cleanup? As we can see from > the following example I have to call *db.Rollback()* for every error > case, and I would really rather only have to call it in one place in > the case. Does your proposal have a solution for this that I missed? > > > *func (db *Database) Transfer(from, to Account, amount int) (err > error) {* > *err = db.Begin()* *when err != nil **goto noTrans* > *if **from* > *.Balance() >= amount {* > * goto noFunds* *}* > *err = **from* > *.Withdraw(amount)* *when err != nil **goto **noWithdraw* > > *err = to.Deposit(amount)* *when err != nil **goto **no**Deposit* > > *err = db.Commit()* *when err != nil **goto **no**Commit* > > *return nil* > *:noCommit:* > *db.Rollback()* > *return fmt.Errorf("cannot commit; %w",
Re: [go-nuts] Re: [RFC] Yet another proposal for Go2 error handling
Hi Jan, thanks for response. On Mon, 5 Jun 2023 01:06:37 -0700 (PDT) Jan wrote: > Repeating Justin's consideration: one of my (and from colleagues I > discuss the topic with) major issues with current error handling is > the repetition of identical code. Your proposal still requires `when > err handle ...` at every statement. Yes, correct. The idea is not to minimise repetition on error handling statement, the "if err != nil", but to minimise repetitive error handling body by grouping it into single handle based on the context of error. > It also doesn't allow for nested > call of functions that return errors -- e.g: `f(g(h(x)))`, where `h`, > `g`, and `f` can return errors (all presumably handled the same way). > I am not sure I understand this, but should not each function handle it on its own? Or should not `f` being called if `g` return an error? If its later, yes, it does not allow for nested handling of error. -- 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/20230617142140.48f4d12c%40inspiro.localdomain. pgp6EUFAPyDPr.pgp Description: OpenPGP digital signature
Re: [go-nuts] Re: [RFC] Yet another proposal for Go2 error handling
Hi Justin, thanks for reviewing, sorry for late response. On Sun, 4 Jun 2023 17:28:29 -0700 (PDT) Justin Israel wrote: > > I don't really understand the comparison between this proposal and > the referenced previous one. If we see one of the first code in the previous proposal design, ... handle err { return fmt.Errorf("copy %s %s: %v", src, dst, err) } r := check os.Open(src) ... There is no explicit link between the "check" keyword and how it will trigger "handle err" later. It is also break the contract between the signature of "os.Open", that return an error in the second parameter and the code that call it. In other words, if someone new to the code, we need to explain to them that os.Open _actually_ return an error as second return value, and that is being checked by "check" using handle. This proposal try to make the link between them clear and keep the code flow explicit and readable, I think. > This new proposal effectively makes you have to handle errors for > every call site, just like we do now, but with the indirect flow of > jumping to a new section of code. And it requires 2 new keywords and > new label syntax to achieve it. Could we not replicate this behavior > the same way with nested local scope functions as the handlers and > just call them with normal if logic? > Some disadvantages of using function to handle error are, first, its expect the call to the function pass the required parameters and handle the returned value back by the caller. Second, the context between the error to be handled and function to be called can be far away (the error function may be defined in different file or outside of current package). When using HandleStmt all required variables that cause the errors and the error itself is in the same scope, there is no flow break between the cause and handler, except the jump that you mentioned above. -- 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/20230617135930.4cc3d0b6%40inspiro.localdomain. pgp6MJ7zT69oF.pgp Description: OpenPGP digital signature
Re: [go-nuts] [RFC] Yet another proposal for Go2 error handling
On Sun, 4 Jun 2023 12:36:20 -0700 Ian Lance Taylor wrote: > On Sun, Jun 4, 2023 at 9:17 AM Shulhan wrote: > > > > I have been reading several proposals about error handling couple of > > months ago and today a light bulb come upon me, and then I write as > > much as I can think. I am not sure if its good or bad idea or even > > possible to implement. > > > > In this post, I will try as concise as possible. > > The full and up to date proposal is available at > > https://kilabit.info/journal/2023/go2_error_handling/ . > > > > Any feedback are welcome so I can see if this can move forward. > > Thanks. Perhaps I misunderstand, but this seems to provide a > different way of writing an if statement and a goto statement. > Instead of writing > > if err != nil { > goto parseError > } > > I can write > > when err handle parseError > In some sense yes, it is identical to writing and combining if and goto statements. The semantic of `when` different on the condition that they evaluate. The `if` statement only continue if expression evaluate to true, the `when` condition only continue if the expression evaluate to non-zero value. So, the "when" statement provide a connection with the handle label. The goto imply that the statements before it fall-through after it. For example, S0 goto1: S1 goto2: S2 Statement S1 will be executed after S0, statement S2 will be executed after S1. Case in example, the following goto example will loop forever, if true { goto goto2 } goto1: println("goto1") goto2: println("goto2") goto goto1 While handle ":name:" scope only on that handle body. The following properties describes how handle and its label are different with goto and its label, * Each of `HandleStmt` MUST be declared at the bottom of function block. * An `HandleStmt` can call other `HandleStmt` as long as the handle is above the current handle and it is not itself. * Any statements below `HandleCallStmt` MUST not be executed. * Unlike goto, each `HandleStmt` is independent on each other, one `HandleStmt` end on itself, either by calling `return` or `handle`, or by other `HandleStmt` and does not fall-through below it. For example, S0 :handle1: S1 :handle2: S2 Statement S0 stop and never fall-through :handle1:. Statement S1 stop and never fall-through :handle2:. Case in example, the following handle will not end with infinite loop, ... when err handle handle2 :handle1: println("handle1") :handle2: println("handle2") handle handle1 > Any change to error handling is going to affect all Go code > everywhere. If we change anything it needs to be a big improvement. > It's not worth changing all Go code everywhere for a small > improvement. After all, Go does work OK today for most people. Agree with that. The original purpose of this proposal in the Abstract [1] is that its not only can be use for handling error but also for handling other control flow. The goals is not to reduce number of lines but to minimise repetitive error handling. > It's > not clear to me that this proposal is a big enough improvement. > Thanks. I am shooting in the dark here and see if it make sense from other perspective. Thanks for reviewing. -- [1] https://kilabit.info/journal/2023/go2_error_handling/#abstract -- 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/20230617134702.1b136cf0%40inspiro.localdomain. pgpnP3sjfGS3P.pgp Description: OpenPGP digital signature
[go-nuts] [RFC] Yet another proposal for Go2 error handling
Dear gophers, I have been reading several proposals about error handling couple of months ago and today a light bulb come upon me, and then I write as much as I can think. I am not sure if its good or bad idea or even possible to implement. In this post, I will try as concise as possible. The full and up to date proposal is available at https://kilabit.info/journal/2023/go2_error_handling/ . Any feedback are welcome so I can see if this can move forward. Thanks in advance. == Background This proposal is based on "go2draft Error Handling". My critics to "go2draft Error Handling" is the missing correlation between handle and check. If we see one of the first code in the design, ... handle err { return fmt.Errorf("copy %s %s: %v", src, dst, err) } r := check os.Open(src) ... There is no explicit link between check keyword and how it will trigger handle err later. It is also break the contract between the signature of os.Open, that return an error in the second parameter, and the code that call it. This proposal try to make the link between them clear and keep the code flow explicit and readable. The goals is not to reduce number of lines but to minimize repetitive error handling. == Proposal This proposal introduces two new keywords and one new syntax for statement. The two new keywords are “WHEN” and “HANDLE”. When = "when" NonZeroValueStmt HandleCallStmt . NonZeroValueStmt = ExpressionStmt ; I am not quite sure how to express non-zero value ; expression here, so I will describe it below. HandleCallStmt = "handle" ( HandleName | "{" SimpleStmt "}" ) . HandleName = identifier . The HandleCallStmt will be executed if only if the statement in NonZeroValueStmt returned non-zero value of its type. For example, given the following variable declarations, var ( err = errors.New(`error`) slice = make([]byte, 1) no1 = 1 no2 int ok bool ) The result of when evaluation are below, when err // true, non-zero value of type error. when len(slice) == 0 // true, non-zero value of type bool. when no1 // true, non-zero value of type int. when no2 // false, zero value of int. when ok // false, zero value of bool. The HandleCallStmt can jump to handle by passing handle name or provide simple statement directly. If its simple statement, there should be no variable shadowing happen inside them. Example of calling handle by name, ... when err handle myErrorHandle :myErrorHandle: return err Example of calling handle using simple statement, ... when err handle { return err } The new syntax for statement is to declare label for handle and its body, HandleStmt = ":" HandleName ":" [SimpleStmt] [ReturnStmt | HandleCallStmt] . Each of `HandleStmt` MUST be declared at the bottom of function block. An `HandleStmt` can call other `HandleStmt` as long as the handle is above the current handle and it is not itself. Any statements below `HandleCallStmt` MUST not be executed. Unlike goto, each `HandleStmt` is independent on each other, one `HandleStmt` end on itself, either by calling `return` or `handle`, or by other `HandleStmt` and does not fallthrough below it. Given the list of handle below, :handle1: S0 S1 :handle2: handle handle1 S3 A `handle1` cannot call `handle2` because its below it. A `handle2` cannot call `handle2`, because its the same handle. A `handle2` can call `handle1`. The `handle1` execution stop at statement `S1`, not fallthrough below it. The `handle2` execution stop at statement "`handle handle1`", any statements below it will not be executed. The following function show an example of using this proposed error handling. Note that the handlers are defined several times here for showing the possible cases on how it can be used, the actual handlers probably only two or three. func ImportToDatabase(db *sql.DB, file string) (error) { when len(file) == 0 handle invalidInput f, err := os.Open(file) when err handle fileOpen // Adding `== nil` is OPTIONAL, the WHEN operation check for NON zero // value of returned function or instance. data, err := parse(f) when err handle parseError err = f.Close() // Inline error handle. when err handle { return fmt.Errorf(`%s: %w`, file, err) } tx, err := db.Begin() when err handle databaseError // One can join the statement with when using ';'. err = doSomething(tx, data); when err handle databaseError err = tx.Commit() when err handle databaseCommitError var outofscope string _ = outofscope // The function body stop here if its not expecting RETURN, otherwise //
Re: [go-nuts] Short Variable Declarations Are Oversold
23 Apr 2023 05:31:25 jlfo...@berkeley.edu : > Short definitions detract from one of Go’s primary goals - readability. I > started using Go in the first place because I wanted a strongly typed > language with explicit type declarations. > > As a result of all this, I’ve started to avoid short variable declarations, > except when I’m initializing a variable inside an > "if"[https://go.dev/ref/spec#If_statements], > "for"[https://go.dev/ref/spec#For_statements], or > "switch[https://go.dev/ref/spec#Switch_statements]” statement, such as > ... > > I doubt if this note will change anybody’s mind but it’s something to think > about. > I agree with OP and probably this is one of the unpopular opinion about Go style. My reasoning is based on three things [1]. First, readability, as also pointed out by OP. Given the following statement t := f() If you are new to code base, you need to know the signature of f to know the type of t. To minimize back and forth when reading code, it is better to declare the type of t before or along with assignment. Yes, some advanced IDE may provide clickable link, unfortunately not all of us use IDE when developing Go. Second, minimize local, temporary variables. Third, prevent subtle bugs [2][3][4] caused by shadowing. For a long term code base, I try to enforce the variable to be declared explicitly with downside more line of codes. [1] https://kilabit.info/journal/2017/05/Go_Informal_Coding_Style#avoid__if_possible [2] https://github.com/golang/go/issues/377 [3] https://github.com/golang/go/issues/20733 [4] https://github.com/golang/go/issues/21291 -- 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/3110d5fb-37e5-4654-a373-df9b480832b5%40gmail.com.
Re: [go-nuts] What's go's convention for specifying the equivolent of configure --prefix?
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 rather than statically set when compile time. The const become default, when the prefix is not set from CLI or any input. -- 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/20221201184729.1adad640%40inspiro.localdomain. pgpjWKYrfZnTz.pgp Description: OpenPGP digital signature
Re: [go-nuts] What's go's convention for specifying the equivolent of configure --prefix?
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: > > 1. go generate > 2. -ldflags="-X 'main.Path=..." > > Both seem to be flawed. For #1, the blog clearly stated that it's > designed for package author, and not for clients (and go generate > doesn't support passing arguments to //go:generate anyways). For #2, > the path can't be a constant. > Whats wrong with const? And could not be global var then? -- 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/20221201171436.5f1922fc%40inspiro.localdomain. pgpQO6OkK7Mda.pgp Description: OpenPGP digital signature
Re: [go-nuts] Proposal for change type Duration int64
On Tue, 22 Nov 2022 02:28:14 -0800 (PST) Nikhilesh Susarla wrote: > Hi, > > type Duration int64 > > The current Duration is int64 and the duration value should never be > less than 0 else it will panic. It would be safe and advisable to > change it to uint64 or so, where at least it would not cause panic. > > Is there any reason for not using uint? > A negative duration is required to compute time.Time-d, using Time.Add(-Duration) [1]. Also, Time.Sub may return negative too. [1] https://pkg.go.dev/time#Time.Sub -- 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/20221122173816.07ed2f06%40inspiro.localdomain. pgpaaCaq6qWJ4.pgp Description: OpenPGP digital signature
Re: [go-nuts] Detecting JSON changes
On Mon, 10 Oct 2022 07:50:20 -0700 (PDT) Slawomir Pryczek wrote: > Hi Guys, > I have 2 json files, A, B. Now i want to detect changes on the root > level. > > File A: {"a":{"b":1, "c":2}, "x":false, ... } > File B: {"a":{"b":1, "c":2}, "x":true, ... } > > I want to be able to see that x is different between A and B and a > stayed the same. What would be the easiest approach? > > Thanks > I can think three options here. One, create a type T that unmarshal the JSON into T and add method that compare each fields. Two, create a type T and unmarshal the JSON into T and use third party library that do struct comparison. Three, diff the text as is using third party library. For option two and three, I have some example here: https://go.dev/play/p/bknJBK4m4CW -- ms -- 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/20221010221608.0518b78f%40inspiro.localdomain. pgpybFhctz21m.pgp Description: OpenPGP digital signature
Re: [go-nuts] tip: data race when running test with coverage
On Sun, 2 Oct 2022 20:45:08 +1100 Rob Pike wrote: > This is a race in new code, then, so please file an issue at > https://go.dev/issue/new > > -rob > Done, https://github.com/golang/go/issues/56006 Thank you for walking me through this. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/20221003112532.0fea60ab%40inspiro.localdomain. pgpCkobBNoM9t.pgp Description: OpenPGP digital signature
Re: [go-nuts] tip: data race when running test with coverage
On Sun, 2 Oct 2022 19:22:21 +1100 Rob Pike wrote: > Apologies, the cover tool calls it -mode but the go command calls it > -covermode. > > go test -covermode=atomic > > -rob > > Got it, thanks, but it still fail with the data race. (ins) 1 $ GOEXPERIMENT=coverageredesign CGO_ENABLED=1 go test -covermode=atomic -race -coverprofile=cover.out ./lib/dns dns.Server: listening for DNS over UDP at 127.0.0.1:5300 dns.Server: listening for DNS over TCP at 127.0.0.1:5300 dns.Server: listening for DNS over TLS at 127.0.0.1:18053 dns.Server: listening for DNS over HTTPS at 127.0.0.1:8443 dns: invalid IP address "localhost" dns: invalid name server URI "://127.0.0.1" dns: invalid IP address "localhost:53" dns: invalid IP address "localhost:53" PASS == WARNING: DATA RACE Read at 0x01e5f04c by main goroutine: internal/coverage/encodecounter.(*CoverageDataWriter).writeCounters.func2() /home/ms/opt/go/src/internal/coverage/encodecounter/encode.go:261 +0x11c runtime/coverage.(*emitState).VisitFuncs() /home/ms/opt/go/src/runtime/coverage/emit.go:539 +0x6bc internal/coverage/encodecounter.(*CoverageDataWriter).writeCounters() /home/ms/opt/go/src/internal/coverage/encodecounter/encode.go:268 +0x16f ... Found 12 data race(s) FAILgithub.com/shuLhan/share/lib/dns0.754s FAIL BTW, from documentation, the -race flag automatically set the -covermode=atomic. -covermode set,count,atomic ... being tested. The default is "set" unless -race is enabled, in which case it is "atomic". ... So I think its redundant to set -race and -covermode=atomic at the same time. -- 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/20221002154034.3ea7e088%40inspiro.localdomain. pgpnCXCcVut4T.pgp Description: OpenPGP digital signature
Re: [go-nuts] tip: data race when running test with coverage
On Sun, 2 Oct 2022 10:41:17 +1100 Rob Pike wrote: > When running coverage in a concurrent program, use the -mode=atomic > flag to avoid data races in the counters. This unavoidably has a > significant performance hit, but it should resolve this race. > > -rob > This flag print "no test files" when running go test, $ GOEXPERIMENT=coverageredesign CGO_ENABLED=1 go test -mode=atomic -race -coverprofile=cover.out ./lib/dns ? github.com/shuLhan/share[no test files] Not sure I am using the flag correctly or not since I cannot find it in the current documentation [1]. [1] https://pkg.go.dev/cmd/go > > On Sun, Oct 2, 2022 at 5:10 AM Shulhan wrote: > > > Hi gophers, > > > > The latest Go tip always fail with data race when running with -race > > and -coverprofile options. > > > > Here is an example of data race output, > > > > > > $ CGO_ENABLED=1 go test -failfast -race -count=1 > > -coverprofile=cover.out ./... > > ... > > == > > WARNING: DATA RACE > > Read at 0x01e5f04c by main goroutine: > > > > internal/coverage/encodecounter.(*CoverageDataWriter).writeCounters.func2() > > /home/ms/opt/go/src/internal/coverage/encodecounter/encode.go:261 > > +0x11c > > runtime/coverage.(*emitState).VisitFuncs() > > /home/ms/opt/go/src/runtime/coverage/emit.go:539 +0x6bc > > internal/coverage/encodecounter.(*CoverageDataWriter).writeCounters() > > /home/ms/opt/go/src/internal/coverage/encodecounter/encode.go:268 > > +0x16f > > internal/coverage/encodecounter.(*CoverageDataWriter).AppendSegment() > > /home/ms/opt/go/src/internal/coverage/encodecounter/encode.go:175 > > +0x8ea > > internal/coverage/encodecounter.(*CoverageDataWriter).Write() > > /home/ms/opt/go/src/internal/coverage/encodecounter/encode.go:71 > > +0x97 > > runtime/coverage.(*emitState).emitCounterDataFile() > > /home/ms/opt/go/src/runtime/coverage/emit.go:573 +0x91 > > runtime/coverage.emitCounterDataToDirectory() > > /home/ms/opt/go/src/runtime/coverage/emit.go:322 +0x310 > > runtime/coverage.processCoverTestDir() > > /home/ms/opt/go/src/runtime/coverage/testsupport.go:39 +0x1c4 > > main.coverTearDown() > > _testmain.go:179 +0x159 > > testing.coverReport2() > > /home/ms/opt/go/src/testing/newcover.go:37 +0xcb > > testing.coverReport() > > /home/ms/opt/go/src/testing/cover.go:83 +0xc74 > > testing.(*M).writeProfiles() > > /home/ms/opt/go/src/testing/testing.go:2053 +0xc6f > > testing.(*M).after.func1() > > /home/ms/opt/go/src/testing/testing.go:1987 +0x30 > > sync.(*Once).doSlow() > > /home/ms/opt/go/src/sync/once.go:74 +0x101 > > sync.(*Once).Do() > > /home/ms/opt/go/src/sync/once.go:65 +0x46 > > testing.(*M).after() > > /home/ms/opt/go/src/testing/testing.go:1986 +0x55 > > testing.(*M).Run.func4() > > /home/ms/opt/go/src/testing/testing.go:1761 +0x39 > > runtime.deferreturn() > > /home/ms/opt/go/src/runtime/panic.go:476 +0x32 > > testing.(*M).Run() > > /home/ms/opt/go/src/testing/testing.go:1771 +0xbb3 > > github.com/shuLhan/share/lib/dns.TestMain() > > /home/ms/go/src/github.com/shuLhan/share/lib/dns/dns_test.go:63 > > +0x5db > > main.main() > > _testmain.go:192 +0x33d > > > > Previous write at 0x01e5f04c by goroutine 9: > > sync/atomic.AddInt32() > > /home/ms/opt/go/src/runtime/race_amd64.s:281 +0xb > > sync/atomic.AddUint32() > > :1 +0x1a > > github.com/shuLhan/share/lib/dns.(*Server).processRequest() > > /home/ms/go/src/github.com/shuLhan/share/lib/dns/server.go:593 > > +0xc67 > > github.com/shuLhan/share/lib/dns.(*Server).ListenAndServe.func1() > > /home/ms/go/src/github.com/shuLhan/share/lib/dns/server.go:187 > > +0x39 > > > > Goroutine 9 (running) created at: > > github.com/shuLhan/share/lib/dns.(*Server).ListenAndServe() > > /home/ms/go/src/github.com/shuLhan/share/lib/dns/server.go:187 > > +0xe6 github.com/shuLhan/share/lib/dns.TestMain.func1() > > /home/ms/go/src/github.com/shuLhan/share/lib/dns/dns_test.go:54 > > +0x44 > > == > > ... > > > > > > There are many lines like that with the same pattern. > > > > In the above snippet, the lib/dns/dns_test.go:63 point this code > > [1], > > > > os.Exit(m.Run()) > > > > So it does not make sense if the data race is in my code. &g
[go-nuts] tip: data race when running test with coverage
Hi gophers, The latest Go tip always fail with data race when running with -race and -coverprofile options. Here is an example of data race output, $ CGO_ENABLED=1 go test -failfast -race -count=1 -coverprofile=cover.out ./... ... == WARNING: DATA RACE Read at 0x01e5f04c by main goroutine: internal/coverage/encodecounter.(*CoverageDataWriter).writeCounters.func2() /home/ms/opt/go/src/internal/coverage/encodecounter/encode.go:261 +0x11c runtime/coverage.(*emitState).VisitFuncs() /home/ms/opt/go/src/runtime/coverage/emit.go:539 +0x6bc internal/coverage/encodecounter.(*CoverageDataWriter).writeCounters() /home/ms/opt/go/src/internal/coverage/encodecounter/encode.go:268 +0x16f internal/coverage/encodecounter.(*CoverageDataWriter).AppendSegment() /home/ms/opt/go/src/internal/coverage/encodecounter/encode.go:175 +0x8ea internal/coverage/encodecounter.(*CoverageDataWriter).Write() /home/ms/opt/go/src/internal/coverage/encodecounter/encode.go:71 +0x97 runtime/coverage.(*emitState).emitCounterDataFile() /home/ms/opt/go/src/runtime/coverage/emit.go:573 +0x91 runtime/coverage.emitCounterDataToDirectory() /home/ms/opt/go/src/runtime/coverage/emit.go:322 +0x310 runtime/coverage.processCoverTestDir() /home/ms/opt/go/src/runtime/coverage/testsupport.go:39 +0x1c4 main.coverTearDown() _testmain.go:179 +0x159 testing.coverReport2() /home/ms/opt/go/src/testing/newcover.go:37 +0xcb testing.coverReport() /home/ms/opt/go/src/testing/cover.go:83 +0xc74 testing.(*M).writeProfiles() /home/ms/opt/go/src/testing/testing.go:2053 +0xc6f testing.(*M).after.func1() /home/ms/opt/go/src/testing/testing.go:1987 +0x30 sync.(*Once).doSlow() /home/ms/opt/go/src/sync/once.go:74 +0x101 sync.(*Once).Do() /home/ms/opt/go/src/sync/once.go:65 +0x46 testing.(*M).after() /home/ms/opt/go/src/testing/testing.go:1986 +0x55 testing.(*M).Run.func4() /home/ms/opt/go/src/testing/testing.go:1761 +0x39 runtime.deferreturn() /home/ms/opt/go/src/runtime/panic.go:476 +0x32 testing.(*M).Run() /home/ms/opt/go/src/testing/testing.go:1771 +0xbb3 github.com/shuLhan/share/lib/dns.TestMain() /home/ms/go/src/github.com/shuLhan/share/lib/dns/dns_test.go:63 +0x5db main.main() _testmain.go:192 +0x33d Previous write at 0x01e5f04c by goroutine 9: sync/atomic.AddInt32() /home/ms/opt/go/src/runtime/race_amd64.s:281 +0xb sync/atomic.AddUint32() :1 +0x1a github.com/shuLhan/share/lib/dns.(*Server).processRequest() /home/ms/go/src/github.com/shuLhan/share/lib/dns/server.go:593 +0xc67 github.com/shuLhan/share/lib/dns.(*Server).ListenAndServe.func1() /home/ms/go/src/github.com/shuLhan/share/lib/dns/server.go:187 +0x39 Goroutine 9 (running) created at: github.com/shuLhan/share/lib/dns.(*Server).ListenAndServe() /home/ms/go/src/github.com/shuLhan/share/lib/dns/server.go:187 +0xe6 github.com/shuLhan/share/lib/dns.TestMain.func1() /home/ms/go/src/github.com/shuLhan/share/lib/dns/dns_test.go:54 +0x44 == ... There are many lines like that with the same pattern. In the above snippet, the lib/dns/dns_test.go:63 point this code [1], os.Exit(m.Run()) So it does not make sense if the data race is in my code. A quick bisect point to this commit [2]. If someone can confirm this, I will submit an issue to GitHub. [1] https://github.com/shuLhan/share/blob/61720a183756bdf5a8af45e7d75116ce7ef188e0/lib/dns/dns_test.go#L63 [2] https://go.googlesource.com/go/+/53773a5d0892be4489b4d5e91bbc8ae61000ada7%5E%21/ -- { "git":"git.sr.ht/~shulhan", "site":"kilabit.info" } -- 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/20221002011006.4ffaaaec%40inspiro.localdomain. pgpLgGLe_dQRK.pgp Description: OpenPGP digital signature
Re: [go-nuts] Go Fonts v2.010
On Fri, 17 Jun 2022 15:37:52 +1000 Nigel Tao wrote: > The Go Fonts were originally released <https://go.dev/blog/go-fonts> > in 2016 and version 2.008 > <https://groups.google.com/g/golang-nuts/c/hGCuDJcQ9ZM/m/tvx5OPzBBwAJ> > came out in 2017. It's taken longer that we'd have liked, but we have > just released version 2.010 as of commit 41969df7 > <https://github.com/golang/image/commit/41969df76e82aeec85fa3821b1e24955ea993001> > : > Thanks! I really like those fonts, especially the monospace one. Since I found it, I use it everywhere :) Do you know any public CDN for gofont/ttfs? Somethings like fonts.google.com or any. -- { "git":"git.sr.ht/~shulhan", "site":"kilabit.info" } -- 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/20220618152419.573f46b0%40inspiro.localdomain. pgpE1CNiqLwNC.pgp Description: OpenPGP digital signature
Re: [go-nuts] Protective buffered channel that never triggers deadlock
On Wed, 13 Apr 2022 01:40:22 -0700 (PDT) Zhaoxun Yan wrote: > Since I found if inserting into a buffered channel could cause a > crash if it is full already > ( now I only use unbuffered channels in work) > https://groups.google.com/g/golang-nuts/c/U8lz6noKkuA > > package main > > var c = make(chan int, 1) > > func main() { > > c <- 1 > c <- 2 //fatal error: all goroutines are asleep - deadlock! > c <- 3 > > } > > I made up a work around that just dumps the new message if the buffer > is full: > > package main > > import ( > "fmt" > "sync" > ) > > type ChanInt struct{ > Ch chan int > Mu *sync.Mutex > } > > var c = ChanInt{make(chan int, 1), new(sync.Mutex)} > > func (ch ChanInt) Fill(k int){ > ch.Mu.Lock() > defer ch.Mu.Unlock() > > if len(ch.Ch) < cap(ch.Ch){ > ch.Ch <- k > } > } > I believe the idiom way is to use select to check if channel is full or not. See "leaky buffer" section on https://go.dev/doc/effective_go#channels . -- { "github":"github.com/shuLhan", "site":"kilabit.info" } -- 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/20220413164344.4de8abf1%40inspiro.localdomain. pgprGXLN9egXW.pgp Description: OpenPGP digital signature
Re: [go-nuts] Golang JSONObject
On Wed, 22 Dec 2021 23:55:43 -0800 (PST) A JI wrote: > Why, when the object of struct is lowercase. I can't fill it and > convert to JSON ? > > https://go.dev/play/p/WZCvC7M5YAp > Is not the object of struct that affect the output of JSON, but the name of field. If the name of field start with lowercase it will not exported by json.Marshal(). See https://go.dev/blog/json and https://pkg.go.dev/encoding/json#Marshal for more information. -- { "github":"github.com/shuLhan", "site":"kilabit.info" } -- 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/20220113003820.2d0d2d12%40inspiro.localdomain. pgpKFovbNwtM7.pgp Description: OpenPGP digital signature
Re: [go-nuts] How to deploy the tour website ?
On Sun, 19 Sep 2021 12:42:42 +0300 mustafa asaad wrote: > Hi, I want to translate the go tour to Arabic I have finished the > first page of the tour and I want to check if everything is good so > when I want to deploy the website to app engine, it's asking me for > money and even when I want to get 90 days free trial my credit card > been rejected! (I think because of my country) also and I don't know I believe the Google Cloud now require credit-card for free trials. > how to deploy the website to app engine, it's confusing > so can you please give instructions to deploy the website the right > way and for free > because that is what you say "This shouldn't cost you anything; the > Tour App usually runs inside App Engine's free quota." > > in https://github.com/golang/website/blob/master/tour/TRANSLATE > Thank you > I am kinda forget the precise step by step instructions, but in general, * Install the gcloud CLI [1]. Make sure you follow the setup at least until "Authorizing Cloud SDK Tools" [2] * Open or activated your Google cloud console account [3] * Create new project on Google cloud: https://console.cloud.google.com/cloud-resource-manager Let say your project name is "go-tour-arabic". * Go to your Tour translation repository, ** Update the "app.yaml", set the "service" to "default", ** Run the following command, $ gcloud --project=go-tour-arabic app deploy --promote app.yaml Wait for several minutes, if everything works correctly, your tour translation should be accessed on https://.appspot.com. I hope that can help. -- [1] https://cloud.google.com/sdk/gcloud/ [2] https://cloud.google.com/sdk/docs/authorizing [3] https://console.cloud.google.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/20210927184426.42f2b799%40inspiro.localdomain. pgpy24rdMKaG8.pgp Description: OpenPGP digital signature
Re: [go-nuts] go-tour-TH cost
On Mon, 27 Sep 2021 17:10:16 +0700 Pallat Anchaleechamaikorn wrote: > Dear Gophers, > > I have a question about my contribution go-tour-TH for Thai language > in GCP app engine. > > I'd like to confirm a bit about the cost. > I've seen in the > https://cs.opensource.google/go/x/website/+/53e4d521:tour/TRANSLATE > > This shouldn't cost you anything; > > [image: Screen Shot 2564-09-27 at 17.08.05.png] > > It still has some cost to me, right? > I just need to confirm, It's ok for me to pay. > As maintainer of go-tour-id, the answer is yes; but it should not cost you that much. Our daily activity is around ~30 active users and the monthly cost is never above ~0.02 USD. Either you have more traffic or there are some unused artifacts that keep accumulating the GCP cost. See the attached screenshot of my GCP billing for reference. -- 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/20210927180621.79ccce6b%40inspiro.localdomain. pgpYW_10vhjH_.pgp Description: OpenPGP digital signature
Re: [go-nuts] Documentation on golang packages and import syntax
Hi Daryl, On Sat, 10 Jul 2021 12:12:41 -0700 (PDT) Daryl Robert Miller wrote: > I have created local packages in support of my main golang program; > it has been challenging to figure out where to put these packages and > how to import them. Obviously this area of Go has changed over the > years so some examples out there are just wrong. The official Go website provides two up-to-date examples on how create package and to import them, * https://golang.org/doc/code * https://golang.org/doc/tutorial/create-module All of them now include creating and using package as part of the Go module. > I got things > working but can find no info on why, so my question is where is an > explaination of how / why the below works (specifically using "main" > prefix): The specification for packages and import can be read on this pages: * https://golang.org/ref/spec#Packages, * https://golang.org/ref/spec#Import_declarations > > go version go1.16.5 darwin/amd64 > Using Visual Studio Code v 1.58.0 on MacOS > > *~/go/src/myproject/main.go* > package main > > import "main/mypackage" > > func main() { > mypackage.Dothis() > } > --- > > *~/go/src/myproject/mypackage/mypackage.go* > package mypackage > > func Dothis() { } > > Assuming that you are not enabling Go module, anything under "$HOME/go/src/" directory will be considered as importable. So, if you have "myproject/mypackage", where "myproject" defined as package "main", then "main/mypackage" is the _import path_ for that package that can be imported by any Go source code under "$HOME/go/src" except by the package itself. -- Shulhan -- 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/20210711162100.17322c80%40inspiro.localdomain. pgp5y4KhDx10L.pgp Description: OpenPGP digital signature
Re: [go-nuts] Understanding how []byte("astring") works
On Mon, 14 Jun 2021 10:24:00 +1000 Amit Saha wrote: > Hi - My main motivation to understand this is i always had to google > this - how to convert a string to a byte slice. > > Is []byte a type that has been defined in the compiler? > > Or, is that an internal level detail that an earlier stage (parsing) > takes care of when the compiler sees that statement? > > Thanks, > Amit > Maybe this blogs can help: https://blog.golang.org/strings -- 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/20210614194026.329ce8b9%40inspiro.localdomain. pgpfSG6EONjHk.pgp Description: OpenPGP digital signature
Re: [go-nuts] Build error from pragma warnings when doing "go build -buildmode=c shared..."
On Thu, 20 May 2021 07:05:22 -0700 (PDT) Aaron Epstein wrote: > Removing gcc 4.1.2 from PATH so it picked up 4.9.4 which resolved > this issue. > > Still would be good to know if it is possible to know which gcc go is > using... > As addition to Manlio reply, for more information about using cgo https://golang.org/cmd/cgo/ Snip from, "... The default C and C++ compilers may be changed by the CC and CXX environment variables, respectively; those environment variables may include command line options." -- 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/20210520215343.6aae484e%40inspiro.localdomain. pgpon8MZr9VsW.pgp Description: OpenPGP digital signature
[go-nuts] Re: error comparison not working on type with field
On Sun, 4 Apr 2021 20:16:15 +0700 Shulhan wrote: > Hi all, > > I found an error that instantiate with type that have field cannot be > compared with the instance of the same type. Here is the test code, > > > type typeErrorWithoutField struct{} > > func (te *typeErrorWithoutField) Error() string { > return "typeError" > } > > type typeErrorWithPublicField struct { > P string > } > > func (te *typeErrorWithPublicField) Error() string { > return "typeErrorWithPublicField" > } > > type typeErrorWithPrivateField struct { > p string > } > > func (te *typeErrorWithPrivateField) Error() string { > return "typeErrorWithPrivateField" > } > > type typeErrorWithIs struct { > p string > } > > func (te *typeErrorWithIs) Error() string { > return "typeErrorWithIs" > } > > func (te *typeErrorWithIs) Is(target error) bool { > return target.Error() == te.Error() > } > > func TestErrors(t *testing.T) { > cases := []struct { > desc string > errerror > target error > }{{ > err:{}, > target: {}, > }, { > desc: "With error created from > {}", err:{}, > target: {}, > }, { > desc: "With error created from > {}", err:{}, > target: {}, > }, { > desc: "With error created from > {}", err:{}, > target: {}, > }} > > for _, c := range cases { > t.Log(c.desc) > t.Logf("err == target: %v\n", c.err == > c.target) t.Logf("errors.Is(err, target): %v\n", errors.Is(c.err, > c.target)) } > } > > > Running this on Go tip, Go 1.16.3, Go 1.15.11 return the same output, > > >ms@inspiro 0 % go test -v -count=1 . > === RUN TestErrors > errors_test.go:69: > errors_test.go:70: err == target: true > errors_test.go:71: errors.Is(err, target): true > errors_test.go:69: With error created from > {} errors_test.go:70: err == target: false > errors_test.go:71: errors.Is(err, target): false > errors_test.go:69: With error created from > {} errors_test.go:70: err == target: false > errors_test.go:71: errors.Is(err, target): false > errors_test.go:69: With error created from > {} errors_test.go:70: err == target: false > errors_test.go:71: errors.Is(err, target): true > --- PASS: TestErrors (0.00s) > === RUN TestTypeErrorWithoutField > errors_test.go:81: err == target: true > errors_test.go:82: errors.Is(err, target): true > --- PASS: TestTypeErrorWithoutField (0.00s) > === RUN TestTypeErrorWithPublicField > errors_test.go:91: err == target: false > errors_test.go:92: errors.Is(err, target): false > --- PASS: TestTypeErrorWithPublicField (0.00s) > === RUN TestTypeErrorWithIs > errors_test.go:101: err == target: false > errors_test.go:102: errors.Is(err, target): true > --- PASS: TestTypeErrorWithIs (0.00s) > PASS > ok git.sr.ht/~shulhan/sandbox/errors 0.001s > > > The only way to make the error comparable and return true is by > implementing method Is() on the type and use the errors.Is to compare > it, or manually by using err.Error() == obj.Error(). > > The thing is, 1) there are some error type that does not implement > the Is() type. One that I stumbled on is ssh.PassphraseMissingError. > 2) some people, like me, assume that errors.Is() working for type > defined error, but in fact it is not. > > Did I miss something? Is this a bug or an expected behaviour? Seems like defined type for error MUST implement the Error method without pointer receiver, otherwise errors.Is is not working as expected. If the type use pointer receiver as in `(e *T) Error()`, one must cast the error `err.(*T)` to check for expected error (assuming that the consumer cannot implement Is() method on the T). The following test show two types that implement error interface with and without pointer receiver. type typeError struct { P in
[go-nuts] error comparison not working on type with field
Hi all, I found an error that instantiate with type that have field cannot be compared with the instance of the same type. Here is the test code, type typeErrorWithoutField struct{} func (te *typeErrorWithoutField) Error() string { return "typeError" } type typeErrorWithPublicField struct { P string } func (te *typeErrorWithPublicField) Error() string { return "typeErrorWithPublicField" } type typeErrorWithPrivateField struct { p string } func (te *typeErrorWithPrivateField) Error() string { return "typeErrorWithPrivateField" } type typeErrorWithIs struct { p string } func (te *typeErrorWithIs) Error() string { return "typeErrorWithIs" } func (te *typeErrorWithIs) Is(target error) bool { return target.Error() == te.Error() } func TestErrors(t *testing.T) { cases := []struct { desc string errerror target error }{{ err:{}, target: {}, }, { desc: "With error created from {}", err:{}, target: {}, }, { desc: "With error created from {}", err:{}, target: {}, }, { desc: "With error created from {}", err:{}, target: {}, }} for _, c := range cases { t.Log(c.desc) t.Logf("err == target: %v\n", c.err == c.target) t.Logf("errors.Is(err, target): %v\n", errors.Is(c.err, c.target)) } } Running this on Go tip, Go 1.16.3, Go 1.15.11 return the same output, ms@inspiro 0 % go test -v -count=1 . === RUN TestErrors errors_test.go:69: errors_test.go:70: err == target: true errors_test.go:71: errors.Is(err, target): true errors_test.go:69: With error created from {} errors_test.go:70: err == target: false errors_test.go:71: errors.Is(err, target): false errors_test.go:69: With error created from {} errors_test.go:70: err == target: false errors_test.go:71: errors.Is(err, target): false errors_test.go:69: With error created from {} errors_test.go:70: err == target: false errors_test.go:71: errors.Is(err, target): true --- PASS: TestErrors (0.00s) === RUN TestTypeErrorWithoutField errors_test.go:81: err == target: true errors_test.go:82: errors.Is(err, target): true --- PASS: TestTypeErrorWithoutField (0.00s) === RUN TestTypeErrorWithPublicField errors_test.go:91: err == target: false errors_test.go:92: errors.Is(err, target): false --- PASS: TestTypeErrorWithPublicField (0.00s) === RUN TestTypeErrorWithIs errors_test.go:101: err == target: false errors_test.go:102: errors.Is(err, target): true --- PASS: TestTypeErrorWithIs (0.00s) PASS ok git.sr.ht/~shulhan/sandbox/errors 0.001s The only way to make the error comparable and return true is by implementing method Is() on the type and use the errors.Is to compare it, or manually by using err.Error() == obj.Error(). The thing is, 1) there are some error type that does not implement the Is() type. One that I stumbled on is ssh.PassphraseMissingError. 2) some people, like me, assume that errors.Is() working for type defined error, but in fact it is not. Did I miss something? Is this a bug or an expected behaviour? -- 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/20210404201615.77d55e97%40inspiro.shul.localdomain. pgphpNOBDWMku.pgp Description: OpenPGP digital signature
Re: [go-nuts] Data Sharing with Non go application
On Sat, 3 Apr 2021 03:42:03 -0700 (PDT) R Srinivasan wrote: > In my app, I would like to use golang for a data aggregator > subsystem. Would like a fast and efficient way of sharing this data > with a consumer subsystem developed in C++. (Both running in the same > system). > > Solution I am pursuing is a shared memory but I am stuck at a > somewhat platform independent way of controlling access to this > shared memory. Semaphores, Mutexes that I search for in the go world > lead to intra process examples. > You should not pursue that, it may be possible, but it will lead to complicated code and hard-to-debug program. My suggestion is put the message bus/broker in between the producer (Go program) and consumer(s) (C++), even thought both running in the same system. It will ease your mind, now and later. My preference for message bus/broker is Nats [1]. > Platforms of interest - Linux and Windows. > > Looking for ideas. > > Thanks, srini > [1] https://nats.io -- 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/20210403191007.7f936764%40inspiro.shul.localdomain. pgpURHrcw3tWz.pgp Description: OpenPGP digital signature
Re: [go-nuts] [Macos/Apple M1] HTTP client requests to ".local" domain adds 5 seconds overhead
On Wed, 31 Mar 2021 01:47:43 -0700 (PDT) Jonathan Hedrén wrote: > I've set up a development environment on my MacBook Pro M1 (running > Big Sur 11.2.3, Go 1.16.2) with a number of small Go/.Net HTTP APIs > that are communication with each other. To replicate our production > infrastructure I've set up /etc/hosts with ".local" domains pointing > to 127.0.0.1. An nginx server then proxies the requests to the APIs. > A self signed certificate is used for https. > > Whenever an HTTP request is sent from a Go application to any of the > ".local" APIs, 5 seconds are added to the response time. This delay > is not added when I use a browser to make the request, neither if I > call an external address (for example google.com) or "localhost" from > the Go code. It only happens when I use http.Client to request a > ".local" domain and the behavior is consistent. > > I've searched the Go standard library for a "5 * time.Second" and > found it only in a few places, including src/net/dnsconfig_unix.go so > I guess it's related to the name resolution. > > Anyone got an idea about what's wrong and how it can be fixed? > > /Jonathan > Previous discussion on this subject: https://groups.google.com/g/golang-nuts/c/BuMYgqMCw8I/m/pIAhmNIWBQAJ -- 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/20210401123914.6e6db5df%40inspiro.shul.localdomain. pgpUFxMeFeNxG.pgp Description: OpenPGP digital signature
Re: [go-nuts] Using nested struct to save master-detail POST request
On Sun, 21 Mar 2021 13:37:18 -0700 (PDT) Hugh Myrie wrote: > I am able to decode the body of a POST request > using json.NewDecoder(r.Body)., then save the result to a database. > > Example: > > type Product struct { > IDint `json:"id"` > Description string `json:"description"` > Price float64 `json:"price"` > Packsize int `json:"packsize"` > Count1 int `json:"count1"` > Bin string `json:"bin"` > Qoh int `json:"qoh"` > } > > items := []Product{} > > err := json.NewDecoder(r.Body).Decode() > if err != nil { > http.Error(w, err.Error(), http.StatusBadRequest) > fmt.Println("Error occurs here") > log.Printf(err.Error()) > return > } > > How can I use a nested struct to produce two slices from an incoming > (master-detail) POST request, in the form: > > [{receipt: 1, date: '01/01/2021', customer: 'Cash' , subtotal: 10.70, > detail: [{receipt: 1, description: 'item1', price: 2.00, qty: 2}, > {receipt: 1, description: 'item2', price: 2.50, qty: 1}, > {receipt: 1, description: 'item3', price: 4.20, qty: 1}] > ] > > I am trying to avoid sending two POST requests, master followed by > detail. > You can add new field with type is slice of struct inside the Product, for example, Details []ProductDetail `json:"detail"` -- 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/20210322112910.206bba4d%40inspiro.shul.localdomain.
Re: [go-nuts] How do you get an update for the tip of a package?
On Wed, 3 Mar 2021 07:06:36 -0800 (PST) Peter Kleiweg wrote: > I try to install a Go program from github at tip. > > This works: > > go get github.com/some/program@HEAD > > But when there is a new push to the repository, and I do this: > > go get -u github.com/some/program@HEAD > > ... I still have the previous version. > > The same with go install. > Most likely, you may have hit the cache on Go proxy server. Either wait for several minutes (1 hour?) or turn off the GOPROXY environment variable. See https://golang.org/ref/mod#module-proxy for more information. -- 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/20210320010353.3ff96b7d%40inspiro.shul.localdomain.
Re: [go-nuts] Local mod version
On Fri, 19 Mar 2021 00:14:40 -0700 (PDT) Pierre Curto wrote: > Hello gophers, > > Trying to locally get the same semver string as if downloading it > from its git repo, and not succeeding. Any pointer? > > Thanks! > This may works or may not works depends on your OS: https://groups.google.com/g/golang-nuts/c/dGa8T9rzpa0/m/iL2kmxkQAgAJ If its not works check the time format, it should be in UTC, and also check your git configuration. -- 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/20210320004900.57e417e6%40inspiro.shul.localdomain.
Re: [go-nuts] Why GO111MODULE=auto go get does not always work?
> On 25 Feb 2021, at 01.40, Peng Yu wrote: > > Hi, > > `GO111MODULE=auto go get` does not always work. What causes this bug? Thanks. > > $ GO111MODULE=auto go get golang.org/x/net/html > $ GO111MODULE=auto go get rsc.io/quote > /Users/xxx/go/src/rsc.io/quote/quote.go:8:8: code in directory > /Users/xxx/go/src/rsc.io/quote/v3 expects import "rsc.io/quote" > https://golang.org/ref/mod#mod-commands If you run the "go get" command on directory that does not contains "go.mod" file, its basically equal to "GO111MODULE=off go get", without module aware. Where do you get the above commands? rsc.io/quote is an example of repository to explain of how Go module works and not works if run without Go module-aware. https://github.com/golang/go/issues/26367 -- 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/03C1A4FC-E82A-48D4-B93E-BC235C28876F%40gmail.com.
Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?
> On 23 Feb 2021, at 12.40, Peng Yu wrote: > > I don’t understand why ping does not have the same problem. Ping is not based > on C library? > Looking at the source code, the ping command on macOS use gethostbyname2() [1][2], while the Go on macOS use C library through getaddrinfo [3][4]. According to this comment [5] on bugs.python.org, the getaddrinfo call mdns library, which means it may prioritise to broadcast through network first (due to local TLD rule) before consulting the /etc/hosts file. That is my guess. Maybe someone who know macOS (or BSD in general) can confirm this behaviour. -- [1] https://opensource.apple.com/source/network_cmds/network_cmds-606.40.2/ping.tproj/ping.c.auto.html [2] https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/gethostbyname.3.html [3] https://go.googlesource.com/go/+/go1.16/src/net/cgo_unix.go#161 [4] https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/getaddrinfo.3.html#//apple_ref/doc/man/3/getaddrinfo [5] https://bugs.python.org/msg258163 > On Mon, Feb 22, 2021 at 11:20 PM Ian Lance Taylor wrote: > On Mon, Feb 22, 2021 at 9:11 PM Peng Yu wrote: > > > > I tried 1.16. > > > > $ go version > > go version go1.16 darwin/amd64 > > > > The problem still exists. When I change mymachine.local to > > mymachine_local, the problem is gone. So somehow, this is related to > > host resolution? It might try to DNS lookup the hostname, when it can > > not find it via DNS then it look up in /etc/hosts? > > On Darwin I believe that by default we pass DNS lookups to the C > library. So I think that what you are seeing is the behavior of the C > library. Try setting the environment variable GODEBUG=netdns=go. > > Ian > > > > On 2/22/21, Ian Lance Taylor wrote: > > > On Mon, Feb 22, 2021 at 12:22 PM Peng Yu wrote: > > >> > > >> I run the following go program using net.Dial(). Depending on whether > > >> I specify a local hostname (defined in /etc/hosts) or an IP. I get > > >> very different runtimes. > > >> > > >> But `ping mymachine.local` resolves the hostname to an IP address > > >> instantaneously. So the two calls of the go program should have the > > >> same runtimes. > > >> > > >> Can anybody reproduce the same runtime problem? Does anybody know what > > >> is wrong with the implementation of net.Dial()? Thanks. > > >> > > >> $ ./main mymachine.local:22 > > >> 2021/02/22 14:14:25 before > > >> 2021/02/22 14:14:30 after > > >> $ ./main 192.168.1.104:22 > > >> 2021/02/22 14:14:30 before > > >> 2021/02/22 14:14:30 after > > >> $ cat main.go > > >> package main > > >> import ( > > >> "net" > > >> "log" > > >> "os" > > >> ) > > >> > > >> func main() { > > >> dialAddr := os.Args[1] > > >> log.Println("before") > > >> _, err := net.Dial("tcp", dialAddr) > > >> log.Println("after") > > >> if err != nil { > > >> log.Fatalln(err) > > >> } > > >> } > > > > > > Which version of Go are you using? What operating system are you running > > > on? > > > > > > It is possible that are running into https://golang.org/issue/35305, > > > which is fixed in 1.16. > > > > > > Ian > > > > > > > > > -- > > Regards, > > Peng > -- > Regards, > Peng > > -- > 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/CABrM6w%3D8Orgj3t4MW3%3DMs7L0vy0nFS_EeGjRZ8n%2BTvQOrHAO9g%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/A0FD8A6A-8159-46C0-AD66-575E2C040AA5%40gmail.com.
Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?
> On 23 Feb 2021, at 12.11, Peng Yu wrote: > > I tried 1.16. > > $ go version > go version go1.16 darwin/amd64 > > The problem still exists. When I change mymachine.local to > mymachine_local, the problem is gone. So somehow, this is related to > host resolution? It might try to DNS lookup the hostname, when it can > not find it via DNS then it look up in /etc/hosts? I see that you run macOS. In the macOS, the local TLD is resolved using multicast DNS. You can try search for "macos local TLD". -- 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/B013250D-8C94-47F4-912A-A42F32E6DC61%40gmail.com.
Re: [go-nuts] Code markup in golang-nuts
> On 21 Feb 2021, at 14.52, Amnon wrote: > > Slightly off topic. > But is there any way to enhance google groups so that it will support > Markdown? Not that I know of. Google groups is mailing list, any thing in and out would be by/for email clients, which is not specific to Google groups. > Or at least provides a simple way to post formatted code without the > indentation being destroyed? > My tips is not using HTML for body (maybe the option name is something like "disable Rich Text format"), use plain text, and it will formatted as is. > People often want post code snippets on this group. > And I have yet to find an easy way to do this. > Most that I have seen use play.golang.org and/or copy-paste the formatted code in email content. -- 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/8A745206-72D8-450A-9EFE-DF754110B375%40gmail.com.
Re: [go-nuts] Contributing to golang based project on github - collaboration best practice
> On 3 Feb 2021, at 10.17, Nicholas Yue wrote: > > Hi, > > I am relatively new to golang coming from a C++/Python world. > > When contributing to C++/Python projects on GitHub, I usually fork the > project, make changes to hit and submit a pull request to the > author/maintainer. > > I found that the above didn't work for me. > > I am hoping to contribute to the following project > > https://github.com/scipipe/scipipe > > I am trying to ascertain if my challenges is because Golang has specific > ways for contribution or the above project is setup differently. I can't tell > as I am new to Golang. > > I clone the forked project to $HOME/go/src/github/scipipe and testing it in > another directory. I found that whenever I run my small test program, it > pulls from some archive rather than my cloned repository and hence is not > able to see the changes I made. > > Is there some special way to import the module so that it picked my clone > directory rather than pulling down a zip archive versioned copy ? > Inside the go.mod file in your test directory, add the "replace" directive. Something like this may works, module mytestmodule replace github.com/scipipe/scipipe => ../path/to/your/clone More on Go modules, * https://blog.golang.org/using-go-modules * https://golang.org/ref/mod -- 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/D4B065B8-12C3-4DDF-8190-13A8D7EA0FAA%40gmail.com.
Re: [go-nuts] golang memory model?
> On 1 Feb 2021, at 22.05, xie cui wrote: > > here is the code: > package main > > import "fmt" > > func main() { > counter := 0 > ch := make(chan struct{}, 1) > closeCh := make(chan struct{}) > go func() { > counter++ //(1) > ch <- struct{}{} > }() > go func() { > _ = <-ch > fmt.Println(counter) //(2) > close(closeCh) > }() > _ =<-closeCh > } > > is (1) happens before (2)? why? I believe the answer is not g. https://golang.org/ref/mem#tmp_7 -- 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/92E42D49-9EB0-444E-AF50-D83F9BD6518E%40gmail.com.
Re: [go-nuts] return own custom error from template while it executed
14 Jan 2021 17:32:37 Vasiliy Tolstov : Hi. I can't find in google how to solve my problem. Inside text/template i want to check some passed data and return some descriptive text if conditions not matching. I don't have ability to check it before template executed. Does it possible? I am not sure your exact problem. So, you have a function that accept data and you want to check the data before passing it to template execution? Why you can not check it before template executed? -- 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/cf99443a-9571-4e9e-90a1-5f2e37d7b75f%40gmail.com.
Re: [go-nuts] Linter for checking 'MVS' of go module
On Wed, 9 Dec 2020, 11:42 xiangdong...@gmail.com, wrote: > Hi all, > > I'm wondering if any linter, or is it practical to make one, checks > whether a go module's code change conforms the minimal version selection > rules, say linter warns a v2 is needed if incompatible changes to APIs are > introduced in the current change under linting? > There is an experiment on tooling called gorelease [1]. I believe its in working-in-progress [2]. [1] golang.org/x/exp/cmd/gorelease [2] https://github.com/golang/go/issues/26420 -- 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/CAMh9%2BYDnGGRAixmxiddNkpX1gbHPSB7NAwatDKP5qCg6z48aJA%40mail.gmail.com.
Re: [go-nuts] How to detect HTTP client stop polling at the server side
> On 27 Nov 2020, at 07.06, Afriyie Abraham Kwabena > wrote: > > Hi, > > Am experiencing data race warning with my pollingworker function below even > though when i build with the -race flag i do not get any error. Any help? > Usually when you got data race warning it will print the line that cause read and write race condition. Pay attention to both lines and I think you will find the cause. It's kind of hard to figure it out only through a single function. It could be in config.Conf or in function that manipulate idtime outside the pollingworker. -- 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/E114D8FD-9EC8-49B3-A7B0-866BA87023EA%40gmail.com.
Re: [go-nuts] How to detect HTTP client stop polling at the server side
> On 18 Nov 2020, at 01.06, Afriyie Abraham Kwabena > wrote: > > Hi, > > The UpdateData function is the HTTP handler for the route which matches the > URL and is called after the mux.Router after receiving an incoming request > matches the incoming request > against the registered route. ... > var idtime = make(map[string]int64) > > > func UpdateData(response http.ResponseWriter, request *http.Request) { > > var ( > localVarHTTPMethod = http.MethodPatch > patchItems model.PatchItem > ) > > id := config.GetIdFromRequest(request) > > if request.Method == localVarHTTPMethod { > > err := json.NewDecoder(request.Body).Decode() > if err != nil { > common.WriteError(response, common.ErrBadRequest) > return > } > > defer request.Body.Close() > > idtime[id] = time.Now().Unix() > We still may have data race here. > > func worker() { > mu.Lock() > for keyid := range idtime { > > d := time.Now().Unix() - idtime[keyid] > if d >= 60 { > > // delete resouce in database after 60 seconds > _ = DeleteNFInstance(ctx, keyid) > } > } > mu.Unlock() > } > ... > // main function > func main() { > r := NewRouter() > > go worker() > > > fmt.Println("Start listening") > fmt.Println(http.ListenAndServe(":8080", r)) > } > > I appreciate your help but am still not able to it work. > Looks like your worker only loop once and then it finished. Either you use time.Sleep() to repeat the loop inside loop or use time.Ticker [1]. [1] https://pkg.go.dev/time#Ticker -- 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/B0663F2A-D51D-43D5-8D63-95C73B51DF90%40gmail.com.
Re: [go-nuts] How to detect HTTP client stop polling at the server side
Hi Afriyie, Looks like you almost there ;) > On 17 Nov 2020, at 20.11, Afriyie Abraham Kwabena > wrote: > > HI, > > This is what I have tried so far but am not able to get the time difference > in seconds. I mean the time differences between the time stored in the > map[string]time.Time and > the current time in seconds. > > code: > > type Server struct { > idtime map[string]time.Time > } > > var my = Server{} > > func main() { > r := mux.NewRouter() > usersData := r.PathPrefix("/users").Subrouter() > usersData.Path("/{id}").Methods(http.MethodPatch).HandlerFunc(UpdateData) > Based on my understanding (I have never use mux before), the UpdateDate function will be running concurrently as goroutine. Lets say that we have three PATCH requests at the same time, there will be three UpdateData running concurrently or in parallel. > fmt.Println("Start listening") > fmt.Println(http.ListenAndServe(":8080", r)) > } > > func UpdateData(response http.ResponseWriter, request *http.Request) { > > var ( > localVarHTTPMethod = http.MethodPatch > patchItems model.PatchItem > ) > > id := config.GetIdFromRequest(request) > > if request.Method == localVarHTTPMethod { > > err := json.NewDecoder(request.Body).Decode() > if err != nil { > common.WriteError(response, common.ErrBadRequest) > return > } > > defer request.Body.Close() > > my.idtime = make(map[string]time.Time) Since the UpdateData is running independently for each request, you should initialize this once, in the main, otherwise each UpdateData routine will reset the idtime variable. > my.idtime[id] = time.Now() > > go func() { > for keyid, t := range my.idtime { > > ts := t.Format(time.RFC3339) > > v, err := time.Parse(time.RFC3339, ts) > if err != nil { > fmt.Println(err) > os.Exit(1) > } > > timeRemaining := getTimeRemaining(v) > > if timeRemaining.S >= 60 { > // delete resouce in database after 60 seconds > deleteResourceUsingIdkey(keyid) > } > } > }() Also, you should move the above goroutine to main, otherwise each call to UpdateData will spawn a new goroutine. If I were you I will use the Unix time [1] instead of Time object, its much simpler `time.Now().Unix() - my.idtime[keyid] >= 60`. BTW, beware of race condition. Test or build your program with "-race" option to see it by yourself. Use sync.Mutex [2] to prevent the write (updating the map) overlap with read (checking the elapsed seconds). [1] https://pkg.go.dev/time#Time.Unix [2] https://pkg.go.dev/sync#Mutex > > common.RespondWith3gppJsonPatchJson(response, http.StatusNoContent, > nil) > } else { > > common.WriteError(response, common.ErrMethodNotAllowed) > return > } Another things that I can't not comment, you can simplify the code by returning-first, which minimize code identation. > } > > type count struct { > S int > } > > func getTimeRemaining(t time.Time) count { > currentTime := time.Now() > difference := t.Sub(currentTime) > > seconds := int(difference.Seconds()) > > return count{ > S: seconds, > } > } > > func deleteResourceUsingIdkey(idkey string) { > // do delete here > } > > Any help. > -- 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/3F1FDD40-AD43-413C-BE21-0BE7EB327F32%40gmail.com.
Re: [go-nuts] How to detect HTTP client stop polling at the server side
> On 16 Nov 2020, at 16.24, Afriyie Abraham Kwabena > wrote: > > Hi , > > You are right but am new to programming and currently this what i have done. > I have an http server handler that receives the PATCH request and stores the > id and the current time stamp of the request. > But my problem is how to write the worker function to do the clean up every X > seconds. > > Code: > func UpdateData(response http.ResponseWriter, request *http.Request) { > > var ( > localVarHTTPMethod = http.MethodPatch > patchItems model.PatchItem > ) > > id := config.GetIdFromRequest(request) > > if request.Method == localVarHTTPMethod { > > err := json.NewDecoder(request.Body).Decode() > if err != nil { > common.WriteError(response, common.ErrBadRequest) > return > } > > defer request.Body.Close() > > var idtime = make(map[string]string) > > delete(idtime, id) // delete if already exist > idtime[id] = time.Now() // store id and time stamp in map You should store idtime inside the server/service type (the one that have HTTP handlers). For example, type Server struct { idtime map[string]string } func (my *Server) UpdateData(...) { ... my.idtime[id] = time.Now() ... } > > // how do i write a worker to the clean up after every X seconds? > Create a function that loop forever and loop the map to check the time, then run the function using goroutine before you start your HTTP server. > } else { > common.WriteError(response, common.ErrMethodNotAllowed) > return > } > } > -- 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/906DFB35-7264-47B0-9E28-42E50694D8B1%40gmail.com.
Re: [go-nuts] How to detect HTTP client stop polling at the server side
> On 14 Nov 2020, at 20.06, Afriyie Abraham Kwabena > wrote: > > Hi, > > My question is about multiple HTTP client polling an HTTP server randomly > with a PATCH request to update a resource at the server running in front of > MongoDB. The clients poll with their different ids and a valid time in their > request. At the server, I can keep their ids and their different times. > How can detect at the server if a specific client stop polling. I would like > to write a function that detect at the HTTP server if a specific client stop > polling and then remove its resources after some time from a database. Am > using gorilla/mux package for the server. Any help, am new to Golang > programming. > I think this is not Go specific, but more like engineering in general. My suggestion is you can store the last time when user request to PATCH endpoint in some storage or internal memory (like map[userID]timestamp) and then have some worker that check the timestamp to clean it up every X seconds or minutes. -- 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/EA52034E-DFED-4853-8720-402BF5E8967F%40gmail.com.
Re: [go-nuts] Distributed go testing (running "go test" as a client)
> On 26 Oct 2020, at 10.32, Craig Silverstein wrote: > > > But in my experimenting the overhead of calling `go test` is quite high: > > `go test -count 1 ; go test -count 1 ` is 50% slower than `go > > test -count1 `. > > Oops, I forgot to take parallelism into account. Once I do, it drops to 30% > slower (which is still significant): > > % time go test ./pkg/... > [...] > 97.100u 9.512s 0:34.22 311.5% 0+0k 31728+2640816io 79pf+0w > > % time sh -c 'find pkg -type d | parallel -iFOO go test -count 1 ./FOO' > [...] > 127.725u 18.722s 0:44.26 330.8% 0+0k 164592+2509424io 443pf+0w > > I'm curious why it's so much slower to run the tests one at a time than all > at once. What work is being redone? -- I'd think anything slow would have > been cached. > You realize that the flag "-count 1" disable the cache, right? Also, why not using the "-p" flag if you want it to be 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/B3C847EA-DC0E-402B-B177-CEE22D9DF0C3%40gmail.com.
Re: [go-nuts] Distributed go testing (running "go test" as a client)
> On 24 Oct 2020, at 22.21, Craig Silverstein wrote: > >> Client: >> FOR EACH pkg in pkgs DO >> (1) result := "go test "+ $pkg; >> (2) POST /$pkg/$result >> DONE > > As I mentioned above: we can certainly do things this way, but there's > a big performance hit to invoking `go test` repeatedly. Oh, I see. Have you try turn off vet doing test? Probably there are other build/test flags that can also be turned off which I am not aware to speeding test up. > > To be clear, I'm not suggesting changing `go test`. My first idea was > to write our own tool, that calls out to the API in > https://golang.org/pkg/testing/ to do the actual mechanics of testing. > But that API doesn't seem to be designed to allow such a thing -- as > one example, the `go test` commandline tool seems to do a lot of work > itself, that our tool would need to duplicate -- and it's unclear how > practical it is to force it. There may well be better ideas we don't > know enough to even think of, though. Another solution that I can think of is by building each package tests binaries in server and distributed it to test machines, so the client does not need to re-build (file read/write, compile, linking, and so on). -- Shulhan -- 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/98963401-FA64-40E1-8833-83F9EA1B7CCA%40gmail.com.
Re: [go-nuts] Distributed go testing (running "go test" as a client)
> On 24 Oct 2020, at 05.57, Craig Silverstein wrote: > > As a way of distributing our go-test run across multiple machines, we are > exploring a client-server architecture. The way we'd like it to work is that > a "go test client" runs on the client machine(s), and repeatedly does the > following: > 1) make an http GET request to "http:///more_tests" > -- the http response is a list of go package specs (e.g. `./web/`, > `./web/internal`) > 2) run the tests in those specs via the equivalent of `go test` > 3) make another request to /more_tests > 4) when /more_tests responds with an empty list, meaning no more tests, > the client emits the test status/summary information > -- it would also be ok to emit the test status/summary for each run, > rather than just at the end > > I could put this client code "above" go test, and (2) could literally be just > exec-ing `go test `. But in my experimenting the overhead of > calling `go test` is quite high: `go test -count 1 ; go test -count 1 > ` is 50% slower than `go test -count1 `. > > So I'd like to put the client code "inside" go test somehow. But I don't > have a good idea how to do that, especially in a way that doesn't depend on > go internals. Alternately, if there is some way to reduce the overhead of > calling `go test` -- I don't know where all the time is going -- that would > be a good solution too. Any ideas/suggestions? > Based on my understanding, my suggestion is you should separate between Go tools (the one that execute "go test") and your test tools (the one that fetch which packages need to tests, run the actual test, and emits the result back to server), not embedded inside the *_test.go files, for the following reason: "go test" should be able to run without depends on test server. Assume that we created a tool called "go-distributed-test" that client executed on the root of repository, $ go-distributed-test /path/to/go-module Client: GET http:///more_tests Server: pkgA,pkgA/B,pkgC => pkgs Client: FOR EACH pkg in pkgs DO (1) result := "go test "+ $pkg; (2) POST /$pkg/$result DONE On step (1), you can read and store the program exit status with their output (stdout and stderr). I hope that helps. I am not going ask _why_ but seems like you got an interesting project to build :) Regards, Shulhan -- 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/FCC123AA-4B2E-4234-9F10-9F76CFF5AE28%40gmail.com.
Re: [go-nuts] comment conversion script? inlncmt.awk?
> 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/E924BC0F-D88F-45C7-A6C2-C689E0123FCA%40gmail.com.
Re: [go-nuts] Running goanalyzer on golang process running inside kubernetes pod
Pada tanggal Sab, 12 Sep 2020 08.52, Siddhesh Divekar < siddhesh.dive...@gmail.com> menulis: > In writing to a file option, we would periodically write the file as it > might turn out to be a huge file > for the entire life of the pod to flush at once > Maybe, the obvious solution here is not using Kubernetes. Create a VM, deploy the binary, ssh into it and run the binary manually, redirect request to VM, and so on. > -- 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/CAMh9%2BYB6TZq6TS7aYAq_EC_c3evXBqnnm-sLBeijcCFNN5Joow%40mail.gmail.com.
Re: [go-nuts] writing to net.Conn tcp socket
Pada tanggal Sab, 12 Sep 2020 02.54, Andy Hall menulis: > if I have multiple clients connected to a tcp server and I wish to write > back to specific connections I can record the net.Conn value and then use > the Write method on it...but when using Println I get the following for two > clients... > > &{{0xc94000}} > &{{0xc94080}} > > which when testing with a simple write doesn't work... > > package main > import "net" > var c net.Conn = "&{{0xc94000}}" > func writeConn(c net.Conn) { > c.Write([]byte(string("Hello\n"))) > } > func main() { > writeConn(c) > } > > ...and results in the following... > > cannot use "&{{0xc94000}}" (type string) as type net.Conn in assignment > > clearly using Println to output the net.Conn is not a viable var to use so > how could I do this ? I intend to record each users net.Conn in a database > which can then be queried as required. > > any help would be most greatly appreciated. > Either I miss something or Go has different socket concept, but last time I learn this is not how the network socket works in general. First, &{{0xc94000}} is the address of a variable. You can't convert an address from string back to variable, because that would be security issue. Usually socket connection is signed integer, in C you can assign integer value to variable let other process write into it. But in Go, connection is an interface/structure. If you want to record each users, you have two options: 1) Let the user send unique ID (for example their user ID or email or username) on first accept. 2) Get unique ID from connection IP address (beware that two or more connection may come from the same IP address). You then must have a map that store unique ID as key and net.Conn as value. So, if you want to send some value to specific user, you query the map first and if exist then you can proceeds. I hope that helps. > -- 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/CAMh9%2BYA1t4ii3QgjMitYKPygQmPCxAJSSaJnctFy5i1t8zKjzA%40mail.gmail.com.
Re: [go-nuts] The latest version of package in pkg.go.dev
> On 15 Aug 2020, at 22.50, Tong Sun wrote: > > Oh, thanks. > > The very reason that I do that is to avoid the following situation: > > for i in `jot 12`; do echo $i > f; git commit -am "$i"; git tag v0.0.$i; done > > $ git tag -l > v0.0.1 > v0.0.10 > v0.0.11 > v0.0.12 > v0.0.2 > v0.0.3 > v0.0.4 > v0.0.5 > v0.0.6 > v0.0.7 > v0.0.8 > v0.0.9 > > If no leading 0s allowed, how do you guys solve the above problem? > $ git tag -l | sort -V -- 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/DCD2A51E-F7AC-473C-863D-BFED17F0DAC5%40gmail.com.
Re: [go-nuts] How to handle large amount of data on the frontend using go template and cassandraDB?
Pada tanggal Kam, 13 Agu 2020 23.21, menulis: > > https://stackoverflow.com/questions/63393803/how-to-handle-large-amount-of-data-on-the-frontend-using-go-template-and-cassand?noredirect=1#comment112097067_63393803 > > I am using *golang* to load data from CassandraDB and send it to the view > component, but it takes almost *2min to load 20k rows of data which is > not good for the end-user*. > > how to handle this amount of data faster? > > This is just an example : > > server.go > > ... > > var tpl = template.Must(template.ParseFiles("index.html")) > > func indexHandler(w http.ResponseWriter, r *http.Request) { > > day:=[]string{"Mon","tue","wed","friday"} // huge data from cassandraDB > tpl.Execute(w, day) > } > > > ... > > > index.html > > > {{range .}} > > {{.}} > > {{ end}} > Have you try by not using template? Probably bytes.Buffer with loop on dara and manual anchor tags. > -- 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/CAMh9%2BYC9ALYK8tZ1pQEMKZ%2BGLrW3n9QYeLiE55v-76pL%3D4_w0g%40mail.gmail.com.
Re: [go-nuts] How url use Html templates?
> On 14 May 2020, at 23.05, Ali Hassan wrote: > > > Html Templates >{{if .Done}} > > >{{end}} > > My question is this , possible that Url > have string value "/HelloQ/home/" which which show as url link option which > you can open if you click on that link > Yes, its possible, but you need to fix your anchor tag with a "href" attribute. I assume you already know that. -- 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/1EF5997F-2751-485A-82D4-22CC86283274%40gmail.com.
Re: [go-nuts] Module versioning on local folder
> On 8 May 2020, at 14.26, Reyhan Sofian Haqqi wrote: > > The question is why you can't have any version inside the shared libs? How do > you shared the libs locally? > > Because we use monorepo. Maybe git tag works since it's also pointing to a > commit hash? but does it works if we use `replace` directive on go.mod file? IMO, you should use replace directive only for VCS to VCS. For example, if you have a fork of module X, and you want to use your fork instead of upstream you can set in go.mod with, replace remote/upstream/X => my/fork/X Setting the right hand side of "replace" directive to filesystem path will make the go tools to use the code in that directory without version. See the wiki page on Modules for more information [1]. > > If the replace directive use local path then I am afraid it will use the > latest pseudo version. > > Yes. This what we use for now. Do you have any suggestions about this? > Treat your shared library as module or in another terms, as a normal project, commit, push changes, or add versioning into it. Here is the steps that I usually do, * Doing development on main module, uncomment the replace directive _only_ if you need to make some changes on your local shared lib. replace your/share/lib => ../lib * After the changes, and the test has passed, comment the replace directive back. // replace your/share/lib => ../lib * Commit the changes in your shared library and push it to the remote repository * Back to main module, run $ go get your/share/lib $ go mod tidy * You should get the latest pseudo-version. Commit it and push to remote repository. In this way, all others developers will get and use the same version of shared lib. One of common mistake is to forgot to comment the "replace" directive back. [1] https://github.com/golang/go/wiki/Modules#when-should-i-use-the-replace-directive -- 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/A915FDC4-3C0B-439C-A9C3-93E913CD1052%40gmail.com.
Re: [go-nuts] Module versioning on local folder
> On 6 May 2020, at 11.11, Reyhan Sofian Haqqi wrote: > > Hi, > > I have a case where we developing inside a monorepo project where we > distribute shared libs locally (without publishing) and we're using replace > directive inside go.mod. What we fear is someone changes the shared libs > logic, it might break other applications that use it because we can't have > any version inside the shared libs module and the applications didn't aware > of any changes inside the shared libs module. Is there any way to add > versioning for this shared libs module? Is it work using pseudo-version? You can use the usual semver on shared libs, and yes it should work with pseudo-version too, as long as you use VCS to publish the changes, The question is why you can't have any version inside the shared libs? How do you shared the libs locally? > > For example, we have a module with pseudo-version > v0.0.0-0001010100-55b989e89570. And then Application A requires this > module. If someone changes the shared libs logic and the pseudo-version > changed to v0.0.0-0001010100-c00dbbc9dadf. What will happen to > Application A which uses module with pseudo-version > v0.0.0-0001010100-55b989e89570? Is it using the code from first > pseudo-version or is it always using the latest code regardless of the > pseudo-version? > If the replace directive use local path then I am afraid it will use the latest pseudo version. -- 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/FA321147-F40E-4F18-AD5F-CB1B2A687A3B%40gmail.com.
[go-nuts] Getting the latest non-tagged version of main module
Sometimes when I push too fast on one of dependencies, the Go proxy can't catch up the latest non-tagged commit on remote server. So, I need to get the latest module version on tip of git commit using the following shell script, #!/bin/sh MODNAME=$(go list -m) DATE=$(date -u -r `git log -n 1 --date=local --pretty=format:'%ct'` +%Y%0m%0d%0H%0M%0S) HASH=$(git log -n 1 --pretty=format:'%h' --abbrev=12) TAG=$(git describe --abbrev=0 --tags 2>/dev/null) if [[ "${TAG}" == "" ]]; then TAG="v0.0.0" else IFS=. read MAJOR MINOR PATCH <<<"${TAG}" PATCH=$((PATCH+1)) TAG=${MAJOR}.${MINOR}.${PATCH} fi echo ${MODNAME} ${TAG}-${DATE}-${HASH} and update the version on go.mod manually to force the proxy to get the defined version. I know that I should test and maybe use "replace" directive before committing any changes to one of dependencies, but one or two things sometimes slip out of our eyes. I have read the documentation on "go help list" and search the web for any alternatives, unfortunately I can't find one. If anyone have any idea about go command that can replace above script, that would be great. Regards, Shulhan -- 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/949F7DDA-0FDC-424F-96B3-79EA49695726%40gmail.com.
Re: [go-nuts] Odd error message - expression in go must be function call
Pada tanggal Kam, 23 Apr 2020 21.30, Matthew Zimmerman menulis: > I was really confused by this error for ~10 minutes or so. Usually when > this happens to me, I missed a closing/opening brace somewhere or I forgot > to add () after my anonymous function declaration to actually run it. > > This time though all the braces were lining up and I had () there > appropriately. I finally gave up on that error and started working on the > next one and when I looked there (using if instead of for with the range > operator) I realized I had a bug fixed it and my first error went away too. > > Not sure if this is anything to be too worried about, but I found it > confusing and wasn't sure if this was worth a bug report or not. > > It's easily reproducible: https://play.golang.org/p/DJKZqMtng4S > > After reading several sentences, I just click the link and can't figured out where the mistake was, and then I read your full email to realize where the error was. Here is another example of confusing error message that I found just today, https://play.golang.org/p/IF5ok20m4X0 You may find the mistake easily by first glance. Usually error like this happen if you have many lines of code with static string here and there, and one single typo. -- 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/CAMh9%2BYCP2NPyWYU56OGp4kMjs15-pFW0GkXhj1OLp_xsZxhyvA%40mail.gmail.com.
[go-nuts] Re: go tip: random high CPU usage on VirtualBox
Pada tanggal Sab, 14 Mar 2020 06.15, Ian Lance Taylor menulis: > On Fri, Mar 13, 2020 at 1:05 AM Mhd Shulhan wrote: > > > > > > > > > On 12 Mar 2020, at 13.13, Mhd Shulhan wrote: > > > > > > > > >> My question is any one have idea how to debug this so I can provide > more > > >> detailed report? > > >> > > >> Thank you in advance. > > > > > > So, I try to debug with gdb 9.1. Here is the sample of stack when the > CPU got high, > > > > > > ... > > > [New LWP 1885] > > > [New LWP 1886] > > > [New LWP 1887] > > > [New LWP 1888] > > > [New LWP 1889] > > > ^C > > > Thread 1 "XYZ" received signal SIGINT, Interrupt. > > > runtime.futex () at > /Users/XXX/share/go/src/runtime/sys_linux_amd64.s:568 > > > 568 /Users/X/share/go/src/runtime/sys_linux_amd64.s: No such file > or directory. > > > (gdb) where > > > #0 runtime.futex () at > /Users/XXX/share/go/src/runtime/sys_linux_amd64.s:568 > > > #1 0x00431666 in runtime.futexsleep (addr=0xd6a3e8 > , val=0, ns=-1) at > /Users/XXX/share/go/src/runtime/os_linux.go:44 > > > #2 0x0040bd9f in runtime.notesleep (n=0xd6a3e8 > ) at /Users/XXX/share/go/src/runtime/lock_futex.go:151 > > > #3 0x0043b858 in runtime.stoplockedm () at > /Users/XXX/share/go/src/runtime/proc.go:1972 > > > #4 0x0043d4c6 in runtime.schedule () at > /Users/XXX/share/go/src/runtime/proc.go:2455 > > > #5 0x0043d89d in runtime.park_m (gp=0xc000166c00) at > /Users/XXX/share/go/src/runtime/proc.go:2691 > > > #6 0x004651fb in runtime.mcall () at > /Users/XXX/share/go/src/runtime/asm_amd64.s:318 > > > #7 0x00465114 in runtime.rt0_go () at > /Users/XXX/share/go/src/runtime/asm_amd64.s:220 > > > #8 0x in ?? () > > > ... > > > > > > Rebuild with `-gcflags=all="-N -l"` and running it again result in the > same stack trace. > > > > > > > > > Looking at git blame for each files does not shown any new commit > introduced since after Go 1.14. Maybe others can look. > > > > > > The next thing I will do is bissecting and rebuild and report again. > > > > According to my bisection, the following commit cause it, > > > > > > 14:18 ~/src/go > > (af1f3b0082...)|BISECTING tokenomy 0 % git bisect good > > 98858c438016bbafd161b502a148558987aa44d5 is the first bad commit > > commit 98858c438016bbafd161b502a148558987aa44d5 > > Author: Ian Lance Taylor > > Date: Tue Feb 25 20:23:15 2020 -0800 > > > > runtime: don't panic on racy use of timers > > > > If we see a racy use of timers, as in concurrent calls to > Timer.Reset, > > do the operations in an unpredictable order, rather than crashing. > > > > Fixes #37400 > > > > Change-Id: Idbac295df2dfd551b6d762909d5040fc532c1b34 > > Reviewed-on: https://go-review.googlesource.com/c/go/+/221077 > > Run-TryBot: Ian Lance Taylor > > TryBot-Result: Gobot Gobot > > Reviewed-by: Michael Knyszek > > > > src/runtime/time.go | 216 > -- > > src/time/time_test.go | 40 ++ > > 2 files changed, 92 insertions(+), 164 deletions(-) > > > > > > Link to CL: https://go-review.googlesource.com/c/go/+/221077 > > > > If anyone have any idea the minimal test code to test it on my VM, I > will test it. > > That seems like a fairly unlikely culprit for significantly increased > CPU usage. Can you double check? > Thanks for the response Ian. I am actually run the bisect twice. I have also test by reverting that commit on top of latest tip and rebuild and redeploy, the result is the random CPU spike doesn't happened anymore. The weird thing is between all 5 services not all of them suddenly consume high CPU, sometimes only one service, sometimes two of them but not three, four, or five at the same time. I will give it one more bisect next Monday. > If you are sure that is the CL, please open a bug report at > https://golang.org/issue. Anything you can give us to recreate the > problem ourselves would be very helpful. Thanks. > Its quite hard for me to create reproducible program since its depends on many third party modules. I try to comprehend the bad CL but its beyond my knowledge. > -- 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/CAMh9%2BYA-7eoOeT94vDC%2BmJJOzcG%2BVTyTbQtKFXaMpfStyd5DQQ%40mail.gmail.com.
[go-nuts] Re: go tip: random high CPU usage on VirtualBox
> On 12 Mar 2020, at 13.13, Mhd Shulhan wrote: > > >> My question is any one have idea how to debug this so I can provide more >> detailed report? >> >> Thank you in advance. > > So, I try to debug with gdb 9.1. Here is the sample of stack when the CPU > got high, > > ... > [New LWP 1885] > [New LWP 1886] > [New LWP 1887] > [New LWP 1888] > [New LWP 1889] > ^C > Thread 1 "XYZ" received signal SIGINT, Interrupt. > runtime.futex () at /Users/XXX/share/go/src/runtime/sys_linux_amd64.s:568 > 568 /Users/X/share/go/src/runtime/sys_linux_amd64.s: No such file or > directory. > (gdb) where > #0 runtime.futex () at /Users/XXX/share/go/src/runtime/sys_linux_amd64.s:568 > #1 0x00431666 in runtime.futexsleep (addr=0xd6a3e8 , > val=0, ns=-1) at /Users/XXX/share/go/src/runtime/os_linux.go:44 > #2 0x0040bd9f in runtime.notesleep (n=0xd6a3e8 ) at > /Users/XXX/share/go/src/runtime/lock_futex.go:151 > #3 0x0043b858 in runtime.stoplockedm () at > /Users/XXX/share/go/src/runtime/proc.go:1972 > #4 0x0043d4c6 in runtime.schedule () at > /Users/XXX/share/go/src/runtime/proc.go:2455 > #5 0x0043d89d in runtime.park_m (gp=0xc000166c00) at > /Users/XXX/share/go/src/runtime/proc.go:2691 > #6 0x004651fb in runtime.mcall () at > /Users/XXX/share/go/src/runtime/asm_amd64.s:318 > #7 0x00465114 in runtime.rt0_go () at > /Users/XXX/share/go/src/runtime/asm_amd64.s:220 > #8 0x in ?? () > ... > > Rebuild with `-gcflags=all="-N -l"` and running it again result in the same > stack trace. > > > Looking at git blame for each files does not shown any new commit introduced > since after Go 1.14. Maybe others can look. > > The next thing I will do is bissecting and rebuild and report again. According to my bisection, the following commit cause it, 14:18 ~/src/go (af1f3b0082...)|BISECTING tokenomy 0 % git bisect good 98858c438016bbafd161b502a148558987aa44d5 is the first bad commit commit 98858c438016bbafd161b502a148558987aa44d5 Author: Ian Lance Taylor Date: Tue Feb 25 20:23:15 2020 -0800 runtime: don't panic on racy use of timers If we see a racy use of timers, as in concurrent calls to Timer.Reset, do the operations in an unpredictable order, rather than crashing. Fixes #37400 Change-Id: Idbac295df2dfd551b6d762909d5040fc532c1b34 Reviewed-on: https://go-review.googlesource.com/c/go/+/221077 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Michael Knyszek src/runtime/time.go | 216 -- src/time/time_test.go | 40 ++ 2 files changed, 92 insertions(+), 164 deletions(-) Link to CL: https://go-review.googlesource.com/c/go/+/221077 If anyone have any idea the minimal test code to test it on my VM, I will test 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/282D59C4-D154-4B8A-862D-77EDCA999750%40gmail.com.
[go-nuts] Re: go tip: random high CPU usage on VirtualBox
> My question is any one have idea how to debug this so I can provide more > detailed report? > > Thank you in advance. So, I try to debug with gdb 9.1. Here is the sample of stack when the CPU got high, ... [New LWP 1885] [New LWP 1886] [New LWP 1887] [New LWP 1888] [New LWP 1889] ^C Thread 1 "XYZ" received signal SIGINT, Interrupt. runtime.futex () at /Users/XXX/share/go/src/runtime/sys_linux_amd64.s:568 568 /Users/X/share/go/src/runtime/sys_linux_amd64.s: No such file or directory. (gdb) where #0 runtime.futex () at /Users/XXX/share/go/src/runtime/sys_linux_amd64.s:568 #1 0x00431666 in runtime.futexsleep (addr=0xd6a3e8 , val=0, ns=-1) at /Users/XXX/share/go/src/runtime/os_linux.go:44 #2 0x0040bd9f in runtime.notesleep (n=0xd6a3e8 ) at /Users/XXX/share/go/src/runtime/lock_futex.go:151 #3 0x0043b858 in runtime.stoplockedm () at /Users/XXX/share/go/src/runtime/proc.go:1972 #4 0x0043d4c6 in runtime.schedule () at /Users/XXX/share/go/src/runtime/proc.go:2455 #5 0x0043d89d in runtime.park_m (gp=0xc000166c00) at /Users/XXX/share/go/src/runtime/proc.go:2691 #6 0x004651fb in runtime.mcall () at /Users/XXX/share/go/src/runtime/asm_amd64.s:318 #7 0x00465114 in runtime.rt0_go () at /Users/XXX/share/go/src/runtime/asm_amd64.s:220 #8 0x in ?? () ... Rebuild with `-gcflags=all="-N -l"` and running it again result in the same stack trace. Looking at git blame for each files does not shown any new commit introduced since after Go 1.14. Maybe others can look. The next thing I will do is bissecting and rebuild and report again. -- 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/3094C38B-39A4-4DBB-B54E-7FD4D6971330%40gmail.com.
[go-nuts] go tip: random high CPU usage on VirtualBox
Hi all, I have Go tip fetch and build every once or more in a week on my local development (office environment). For local testing, I have VirtualBox setup with all third parties. The host machine is macOS Catalina version 10.15.3, Model Identifier: MacBookPro14,1 Processor Name: Dual-Core Intel Core i5 Processor Speed: 2,3 GHz Number of Processors: 1 Total Number of Cores:2 L2 Cache (per Core): 256 KB L3 Cache: 4 MB Hyper-Threading Technology: Enabled Memory: 8 GB Boot ROM Version: 204.0.0.0.0 The guest machine is Arch Linux on VirtualBox 6.1.4 r136177 (Qt5.6.3), 5.5.7-arch1-1 #1 SMP PREEMPT Sat, 29 Feb 2020 19:06:02 + x86_64 GNU/Linux HPET:disabled CPUProfile: host Chipset: piix3 Firmware:BIOS Number of CPUs: 1 PAE: disabled Long Mode: enabled Triple Fault Reset: disabled APIC:enabled X2APIC: enabled Nested VT-x/AMD-V: disabled ACPI:enabled IOAPIC: enabled BIOS APIC mode: APIC Time offset: 0ms RTC: local time Hardware Virtualisation: enabled Nested Paging: enabled Large Pages: enabled VT-x VPID: enabled VT-x Unrestricted Exec.: enabled Paravirt. Provider: None Effective Paravirt. Prov.: None At the guest, we have five Go services that depends on Nats, Redis, and MySQL. The problem is at random time one or two random service(s) will run with high CPU usage. There is no issue when building with Go 1.14. I have add "net/http/pprof" to each of them and try to run the profiling tools from host to service that run with high CPU, but it can't reach the service with the following error, Fetching profile over HTTP from http://192.168.56.10:6079/debug/pprof/profile 192.168.56.10:6079/debug/pprof/profile: Get "http://192.168.56.10:6079/debug/pprof/profile": net/http: timeout awaiting response headers failed to fetch any source profiles My question is any one have idea how to debug this so I can provide more detailed report? Thank you in advance. -- 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/B211F6E8-A7F5-4EC2-8FEC-91DBF1919A20%40gmail.com.
Re: [go-nuts] Language proposal: labelled "with" statements to help make test code easier to write
Pada tanggal Min, 1 Mar 2020 01.11, Warren Stephens < wsteph...@prognoshealth.com> menulis: > I often write a function or module to handle some process that takes 3 or > 4 steps to complete. > > After I am happy with the code I then proceed to write tests for the code, > but find that I am compelled to chop the code into pieces in order to > simplify the test code > -- thereby losing the nice top down readability with which I started. > > The influence that test code has on the structure of the application code > is highly undesirable. > > Test code should not exert so much influence over how the primary code is > written. > In my experiences, it is a good things that the test code has influence to the structure of application code, because if the code can not be easily tested, there is something wrong with how I solve the problem, or maybe I need to break it down into smaller unit and test only some parts of unit. > The labelled *with* statements would allow for a test to be written > specifically for each step of a function. > > Each test would begin at the *with* statement, providing the variables > and values required, and end at the next *with* statement or return > statement. > Now the application code are mixed with the test functionality. This is not good design. Testing and application code are different domain, even if its in the same repository. > Each step of a function could be tested (or not) without having to > refactor the function into testable pieces > which would lose the natural structure of the original code. > -- 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/CAMh9%2BYBgYzLW6p9bqk5gR--GjVdwviBUC7a%2BrKs-7srNfx5J9g%40mail.gmail.com.
[go-nuts] [Proposal] database/sql: add interface that unite DB and Tx
## Problem At some point we have a function that receive an instance of database connection to query rows in specific table. Let's say that function F() accept DB that query table T. If function F() called with DB instance, it will query only rows that has been committed into database. IF function F() called with Tx instance, it will query all rows including the one that has not been committed yet into database. Since DB and Tx are different types, we will have two functions that almost have identical code, func F(db *sql.DB) (output int) { q := `SELECT … FROM T WHERE …` err := db.QueryRow(q).Scan() … return output } func FWithTx(tx *sql.Tx)(output int) { q := `SELECT … FROM T WHERE …` err := tx.QueryRow(q).Scan() … return output } ## Proposed solution Add an interface Session (the name is not fixed yet) to package sql with the following signature, type Session interface { func Exec(query string, args ...interface{}) (Result, error) func ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error) func Prepare(query string) (*Stmt, error) func PrepareContext(ctx context.Context, query string) (*Stmt, error) func Query(query string, args ...interface{}) (*Rows, error) func QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) func QueryRow(query string, args ...interface{}) *Row func QueryRowContext(ctx context.Context, query string, args ...interface{}) *Row } Session interface is combination of DB and Tx that contains all identical methods. ## Rationale Without Session, user will have two functions that have the same code, By using Session, we can minimise duplicate code in the user level. for example using the previous problems definition the function F() become one, func F(session sql.Session)(output int) { q := `SELECT … FROM T WHERE …` err := session.QueryRow().Scan() … return output } ## Discussion Any thought about this proposal? -- 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/C8AB29FF-7A85-445A-B09E-A0E7CB322A4C%40gmail.com.
Re: [go-nuts] http: superfluous response.WriteHeader call
On Fri, 1 Nov 2019, 00:13 , wrote: > help me! > > web connect database and show view. when press f5 repeatedly > command line show http: superfluous response.WriteHeader > call... > My guess is that you call response.WriteHeader in your code. Check again, and make sure its only call once. -- shuLhan > -- 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/CAMh9%2BYDXYFnPKwLHqiSVbZWcL_3TjcJdO%3Dcc8Bd3fjAtJurYnQ%40mail.gmail.com.
Re: [go-nuts] How to kill running function from core golang libraries
On Fri, 1 Nov 2019, 21:07 burak sarac, wrote: > I have a go routine running something like 'hash.sum(data)' using import > "hash" that I want to terminate immediately in case of user wants to > kill, I can not send channel to notify. > I have not tried this, but you can use a combination of defer, panic and recover to unroll the process. The recover function is inside calculate, and the for-loop is running in goroutine before calculate. defer func() { recover() } go loop() calculate() Inside the loop() you will call panic("terminate"). -- Shulhan > -- 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/CAMh9%2BYA%3DYW9gp6gtduRMyh_Zu567CJ97r8PcR-Wzp9HEz2%2BxHg%40mail.gmail.com.
Re: [go-nuts] How to mock functions in Go ?
On Fri, 20 Sep 2019, 18:58 Nitish Saboo, wrote: > Tried running you code, it's failing: > > --- FAIL: TestF (0.00s) > test.go:43: got ubuntu, want testing > FAIL > If that's the case I think you should learn about programming in general first, before learning how to mock a function. I believe there are many online tutorial in the web. > > -- 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/CAMh9%2BYA8yNSU0K_z%2BsJNFmy0K-nptak6aBqsupCC06fmR%2B%3DS9Q%40mail.gmail.com.
Re: [go-nuts] How to mock functions in Go ?
> On 20 Sep 2019, at 17.21, Nitish Saboo wrote: > > I have a function in Go that I want to unit test but that function contains > os.Hostname().Hence i thought of mocking os.Hostname. > > Example: > > func F(){ > hostname, _ := os.Hostname() > } > > I tried something like this: > > var osHostname = os.Hostname > > func TestF(t *testing.T) { > expected := "testing" > defer func() { osHostname = os.Hostname }() > osHostname = func()(string, error) { return "testing", nil } > actual := F() > assert.Equal(t,expected,actual) > } > > But this doesn't work.Can someone please point me in the right direction? I have two notes about your code. First, F() should have return values but its not. Second, F() should use osHostname not os.Hostname. The following pseudocode should works, ``` var osHostname = os.Hostname func F() (string, error) { return osHostname() } func TestF(t *testing.T) { orgGetHostname := osHostname osHostname = func() (string, error) { return "testing", nil } defer func() { osHostname = orgGetHostname }() exp := "testing" got, _ := F() if exp != got { t.Fatalf("got %s, want %s", got, exp) } } ``` -- 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/7F40F7C1-6C32-4513-966E-D5C91AAD832C%40gmail.com.
Re: [go-nuts] Is there a preferred REDIS driver or go psckage?
In the following redis page: https://redis.io/clients#go you can see list of Go packages, the recommended ones are marked with star; while package with smile icon mark packages that have activities within last six months. -- 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/A06B7048-8FB1-4A33-AF32-77A318857467%40gmail.com.
Re: [go-nuts] Broken links on some blogs
On Sun, 18 Aug 2019, 06:04 Ian Lance Taylor, wrote: > On Tue, Aug 13, 2019 at 11:13 AM Shulhan wrote: > > > > I am not sure where or how to report this problem, but all of the links > > from the following blog > > > > https://blog.golang.org/upcoming-google-io-go-events > > > > are 404. Some of examples, > > > > * http://code.google.com/events/io/2010/ > > * http://code.google.com/events/io/2010/bootcamp.html > > * http://code.google.com/events/io/2010/sessions/go-programming.html > > * http://code.google.com/events/io/2010/officehours.html > > > > There are probably other links in other posts that also broken. Let me > > known if I should open an issue and/or check other links. > > Thanks! I sent https://golang.org/cl/190717 for this particular > problem. Please do feel free to open issues for other broken links > you happen to find, or just send a pull request. > Thanks Ian, I will open new issue if I found other blog post with broken links. > -- 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/CAMh9%2BYBhWPkec31JwQ7Ue_Xs20rPaEM5sOMK9WuvjBwcJF%2B%3DCA%40mail.gmail.com.
[go-nuts] Broken links on some blogs
Hello gophers, I am not sure where or how to report this problem, but all of the links from the following blog https://blog.golang.org/upcoming-google-io-go-events are 404. Some of examples, * http://code.google.com/events/io/2010/ * http://code.google.com/events/io/2010/bootcamp.html * http://code.google.com/events/io/2010/sessions/go-programming.html * http://code.google.com/events/io/2010/officehours.html There are probably other links in other posts that also broken. Let me known if I should open an issue and/or check other links. -- { "github":"github.com/shuLhan", "site":"kilabit.info" } -- 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/20190814011259.5a10882e%40kilabit.local.
Re: [go-nuts] How to mock functions in Go ?
On Thu, 1 Aug 2019 05:09:54 -0700 (PDT) Nitish Saboo wrote: > Hi, > > How can we mock a function in Go like os.Hostname() or os.Getwd() ? > Any framework or Library that we can use for mocking the function > calls ? > I usually does something like these, var getHostname = os.Hostname and in test file, getHostname = func() { return "something", nil // or a variable } -- { "github":"github.com/shuLhan", "site":"kilabit.info" } -- 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/20190801214848.00e217cb%40kilabit.local.
Re: [go-nuts] Some issues with UDP and Go
On Sun, 7 Apr 2019, 04:24 John Dreystadt, wrote: > I wrote some sample code (at the end of this message) to see how UDP > worked in the Go environment. And I wound up with some issues because > things did not seem to work as I expected. I am running go1.11.2 on both a > Windows box and a Ubuntu box. > > Issue 1, when I call WriteMsgUDP with both a regular buffer and an out of > band buffer, I get back the length as I expected. But I never see any out > of band data on the read side. Is this a known error or am I just missing > something? > > Issue 2, when I send a UDP message longer than the buffer at the receiving > end I get an error on the Windows side along with a bit set in flags. The > Ubuntu side does not report an error but does set a bit (but a different > one). Even more odd, the Windows side does not return the address of the > sending machine when this error occurs. While having one report an error > while not the other is not unreasonable, losing the address of the sending > machine seems really bad unless it just is not there on Windows. > > Issue 3, the documentation for the flags return from ReadMsgUDP just says > "the flags set on the message" which is pretty short and does not even > indicate who set the flags. Maybe something like "the flags are set on the > message by the network stack and are operating system dependent". > > I used two copies of the following program running to see the issues. To > replicate, first run one without any flags and then run the second with > -mode=wr . > > package main > > import ( > "errors" > "flag" > "fmt" > "net" > ) > > var rfserver = flag.String("RFS", "127.0.0.1:6000", "Read First Server > Name:Port Number") > var wfserver = flag.String("WFS", "127.0.0.1:6001", "Write First Server > Name:Port Number") > > type modeValue string > > func (mode *modeValue) String() string { > return string(*mode) > } > > func (mode *modeValue) Set(s string) error { > switch s { > case "rw": > *mode = modeValue(s) > return nil > case "wr": > *mode = modeValue(s) > return nil > default: > return errors.New("Mode must be rw or wr") > } > } > > var mode modeValue > > func main() { > mode = modeValue("rw") > flag.Var(, "mode", "rw for read then write and wr for the reverse") > flag.Parse() > fmt.Println("Parameters", *rfserver, *wfserver, mode) > > rfudpaddr, err := net.ResolveUDPAddr("udp", *rfserver) > if err != nil { > panic(err) > } > wfudpaddr, err := net.ResolveUDPAddr("udp", *wfserver) > if err != nil { > panic(err) > } > var rudpaddr, wudpaddr *net.UDPAddr > if mode == "rw" { > rudpaddr, wudpaddr = rfudpaddr, wfudpaddr > } else { > wudpaddr, rudpaddr = rfudpaddr, wfudpaddr > } > pc, err := net.ListenUDP("udp", rudpaddr) > if err != nil { > panic(err) > } > > if mode == "rw" { > buffer := make([]byte, 5) > oobbuffer := make([]byte, 5) > n, oobn, flags, addr, err := pc.ReadMsgUDP(buffer, oobbuffer) > fmt.Println("n,oobn,flags,addr,err", n, oobn, flags, addr, err) > n, oobn, flags, addr, err = pc.ReadMsgUDP(buffer, oobbuffer) > Just quick note, I think you should reset both buffer and oobbuffer on subsequence read. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] The aggresiveness of Go module
I have a temporary directory, lets call them "~/tmp/sandbox/go/src", to test Go behaviour here and there that sometimes I always forget. This time I want to know how the interface{} type works. I create directory "interface" then inside it I create "main.go" file. When running it with "go run ." it display an error, go: cannot find main module, but found .git/config in /home/ms to create a module there, run: cd ../../../../.. && go mod init I know how to solve this, either turn off GO111MODULE or set GOPATH. Now imagine the scenario when you want to teach Go programming to new learner, let say students. After you introduce them to Go syntax, and ready for practice you inform them that, the first thing to do to create a Go program are, - Create directory - Create module using "go mod init" - and so on. Well, if I am the student, I will ask `What is "go mod"`?, and then instead of practicing programming, we take time to learn the ecosystem of Go. Is this the goal of Go? What do you think? -- { "github":"github.com/shuLhan", "site":"kilabit.info" } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How to lower listen backlog for tcp socket
On Thu, 21 Mar 2019 23:18:34 +0800 Wangbo wrote: > I try to use net.ListenConfig, but fail > can someone give example ? > What do you mean by fail? What have you try? Have you tried using syscall.Listen [1] ? [1] https://golang.org/pkg/syscall/#Listen -- { "github":"github.com/shuLhan", "site":"kilabit.info" } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] [ANN] rescached: resolver (DNS) cache daemon
rescached is a daemon that caching internet name and address on local memory for speeding up DNS resolution. rescached primary goal is only to caching DNS queries and answers, used by personal or small group of users, to minimize unneeded traffic to outside network. This release is dedicated to Archer and github user `chadberg` and `skydrome` who keeps reporting issues and may still use the original version. Whoever you are, thank you! = Features List of current features, - Enable to handle request from UDP and TCP connections - Enable to forward request using UDP or TCP - Load and serve addresses and hostnames in `/etc/hosts` - Load and serve hosts formated files inside directory `/etc/rescached/hosts.d/` - Blocking ads and/or malicious websites through host list in `/etc/rescached/hosts.d/hosts.block` - Support loading and serving master (zone) file format from `/etc/rescached/master.d` - Integration with openresolv - Support DNS over HTTPS (DoH) (draft 14) For more information see https://github.com/shuLhan/rescached-go . = Background The original rescached software is written in C++ [1], written back since 2009. Over time, the more feature to add, the more painful to maintenance and test it. I can't trust and remember my own code after being long enough not meddling with it. After having experienced with Go and confidence enough, I try to porting it. The time its take to porting it is about one month. The first step is to create DNS library [2] that support client and server model. Everything else in rescached is just a layer to manage caches from DNS responses on top of the library. Adding new features, like loading master file, integration with openresolv and DoH is take about one months. Thanks to Go standard packages that provide user all the required libraries for HTTP and TLS. Overall I am very happy working with Go. = Benchmark == resolverbench Result of benchmarking with local blocked host file, master ms 0 % ./resolverbench 127.0.0.1:53 scripts/hosts.block = Benchmarking with 27367 messages = Total: 27367 = Failed: 0 = Elapsed time: 1.053238347s == dnstrace Result of benchmarking with 1 query and 100 concurrent connections using dnstrace [3], master ms 0 % dnstrace --recurse --codes --io-errors -s 127.0.0.1:53 -t A -n 1 -c 100 redsift.io Benchmarking 127.0.0.1:53 via udp with 100 conncurrent requests Total requests: 100 of 100 (100.0%) DNS success codes: 100 DNS response codes NOERROR:100 Time taken for tests:10.318186376s Questions per second:96916.3 DNS timings, 100 datapoints min:0s mean: 1.017194ms [+/-sd]:770.525µs max:39.845887ms DNS distribution, 100 datapoints LATENCY | | COUNT +-+-++ 131.071µs | | 1722 393.215µs | | 115890 655.359µs | ▄ | 185089 917.503µs | ▄▄▄ | 316551 1.179647ms | ▄ | 300305 1.441791ms | | 31218 1.703935ms | ▄▄ | 12005 1.966079ms | ▄ | 6387 2.228223ms | ▄ | 5007 2.490367ms | | 3196 2.752511ms | | 2573 3.014655ms | | 2486 3.276799ms | | 2012 3.538943ms | | 1814 3.801087ms | | 1806 4.063231ms | | 1512 4.325375ms | | 1099 4.587519ms | | 1077 4.849663ms | |785 5.111807ms | |759 5.373951ms | |901 5.636095ms | |765 5.898239ms | |874 6.160383ms | |654 6.422527ms | |476 6.684671ms | |351 6.946815ms | |294 7.208959ms | |245 7.471103ms | |292 7.733247ms
Re: [go-nuts] Deferring a close that can fail
On Tue, 19 Mar 2019 16:57:51 -0700 (PDT) David Collier-Brown wrote: > It's a known bad thing to defer a close for anything buffered, as > discussed at > https://www.joeshaw.org/dont-defer-close-on-writable-files/ but some > constructs lack a Sync() call. > > For example, I have code like > ifDB, message, err := OpenInflux(server, debug) > if err != nil { > // If this fails, fail fast so we notice > panic(fmt.Errorf("failed to open and ping influxDB, > %s %v", message, err)) > } > defer func() { > err = ifDB.Close() > if err != nil { > // This may be a harmless, very bad thing > panic(fmt.Errorf("failure closing connection > to influxDB, %v", err)) > } > }() > > > which closes an influxDB database, but will panic if the close fails. > > Is there an idiomatic way to address this? Any Close on file or connection should be called only if only the call to Open function or method success. You have two options here: either you remove the panic when Close is error (only logging it) or call Close only if Open is success. I usually prefer the latter. -- { "github":"github.com/shuLhan", "site":"kilabit.info" } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] [CoC] screenshot images. Lazines or incompetence?
On Mon, 11 Mar 2019 14:11:32 +0100 Reto Brunner wrote: > On Mon, Mar 11, 2019 at 07:46:27PM +0700, Shulhan wrote: > > I like to read email before sleep, keeping up-to-date with recent > > discussion and what not. > > How are you able to cope with mailing lists? > I find list messages seriously unreadable with the gmail app, due to > the lack of threading. > As long as its text and people keep bottom posting its works quite well, I can scroll from top to bottom easily. But, when its top posting sometimes I lost the context, and need to click the "hidden" quoted text below it. If its unreadable, I just ignore it. -- { "github":"github.com/shuLhan", "site":"kilabit.info" } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] [CoC] screenshot images. Lazines or incompetence?
On Mon, 11 Mar 2019 13:02:28 +0100 Reto Brunner wrote: > On Mon, Mar 11, 2019 at 04:36:32AM -0700, Manlio Perillo wrote: > > I consider polite to use the interleaved reply style and to trim the > > original message as much as possible. It requires time and > > thinking, something that seems to be rare nowadays. > > And yet you are right now also not doing it, adding to the problem. > > Then again, not everyone uses a mail client where things like this is > obvious, some prefer to use gmail for example. Now, gmail doesn't > care about threading and automatically top / bottom posts (not sure > which direction). > > People aren't in the 80s anymore where a 72 char limit was nice, due > to the screen size. Automatic line wrapping is a thing since a while, > so are clients that strip (or hide) the quoted message trail. > True. But we are in the era of mobile phone where screen size is smaller again (for some phone, maybe). I like to read email before sleep, keeping up-to-date with recent discussion and what not. Keeping the email short and structured kinda plus for me, since most MUA on phone does not handle threading very well. > So in short: get used to it :) > Most of the time, I get used to it. -- { "github":"github.com/shuLhan", "site":"kilabit.info" } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Re: url.parse issue if the first character of a url is a number
On Tue, 12 Feb 2019 09:35:38 -0800 (PST) jake6...@gmail.com wrote: > I can not speak directly to Go's version, but according to the IETF > standards, a domain name can not start with a digit. So they are in > fact malformed. > It used to, but then RFC 1123 section 2.1 relaxed the syntax to allow digit [1], The syntax of a legal Internet host name was specified in RFC-952 [DNS:4]. One aspect of host name syntax is hereby changed: the restriction on the first character is relaxed to allow either a letter or a digit. Host software MUST support this more liberal syntax. This was also confirmed by RFC 2181 section 11 [2], The DNS itself places only one restriction on the particular labels that can be used to identify resource records. That one restriction relates to the length of the label and the full name. The length of any one label is limited to between 1 and 63 octets. A full domain name is limited to 255 octets (including the separators). [1] https://tools.ietf.org/html/rfc1123#page-13 [2] https://tools.ietf.org/html/rfc2181#section-11 -- { "github":"github.com/shuLhan", "site":"kilabit.info" } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Contributors wanted: Quantitative performance improvement study
On Fri, 1 Feb 2019 15:13:35 -0800 (PST) thomb...@gmail.com wrote: > > However, there has been no comprehensive quantitative study on this > so far that I am aware of. > Did you mean like Web Framework Benchmark by TechEmpower? [1] [1] https://www.techempower.com/benchmarks/#section=intro=ph=plaintext -- { "github":"github.com/shuLhan", "site":"kilabit.info" } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How to write unit test for init()?
On Tue, 27 Nov 2018, 11:08 Vast Peng > > when importing *component*, Golang will call *init() *automatically. > One way to do it is by moving the init into another function and call it from init. That way you can create test for the function. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] At runtime, tell if a package path belongs to stdlib ?
On Mon, 26 Nov 2018 07:07:34 -0800 (PST) clementauger...@gmail.com wrote: > HI, > > I m looking for a reliable way to determine if a package path string > belongs to the stdlib or not. > > It happens at runtime, the program can not access its sources. > > I m thinking to write package that stores those information into > package variables, into a map[go version][]packagesPaths. > > Do you have any suggestions to achieve that ? > > I digged into go/types, loader etc but i did find the desired api. > > Thanks! > Here is a function to get list of packages under $GOROOT/src. [1] [1] https://github.com/shuLhan/beku/blob/master/env.go#L398 -- { "github":"github.com/shuLhan", "site":"kilabit.info" } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Using git-codereview with GitHub
On Wed, 21 Nov 2018 14:48:20 + Paul Jolly wrote: > > There is hub [1]. If you have not heard it, its work by > > repo-branch-commits, > > Thanks, but as I understand it, this tool is branch-based. > > I want to make my workflow oriented around single commits (on a local > branch). > I think that can be solved with an instruction on how one should create a PR, and mostly a PR is per single commit. I rarely see, many commits in PR except in internal/private repository. -- { "github":"github.com/shuLhan", "site":"kilabit.info" } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Using git-codereview with GitHub
On Wed, 21 Nov 2018 13:49:32 + Paul Jolly wrote: > > What I'm ultimately trying to achieve is something akin to Gerrit's > relation chain. That is, have a number of commits on a local branch, > and have each commit correspond to a GitHub PR. Would involve creating > some PR-specific branches etc. > There is hub [1]. If you have not heard it, its work by repo-branch-commits, - create a branch or fork - commit and push to that branch - run `hub pull-request --base --head ` [1] https://github.com/github/hub PS: It was written in Go. -- { "github":"github.com/shuLhan", "site":"kilabit.info" } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] spanish tour.golang.org is down
On Wed, 17 Oct 2018 06:49:09 -0700 Ian Lance Taylor wrote: > On Wed, Oct 17, 2018 at 1:29 AM, Gorka Guardiola > wrote: > > > > Other languages seem to be ok. > > The link has been down with a 404 error for quite some time. > > Does anybody know why? > > I don't know but it's been down for a while: > https://github.com/golang/tour/issues/596 . > > Francesc, any idea who owns the Spanish language version of the tour? > > Ian > According to my notes [1], it should be https://github.com/rcostu/go-tour-es [1]https://docs.google.com/document/d/1r6qYP9xey-u0vKXD8xxNaTWn-f_0WI1CtoDm0trx8ZQ/edit -- { "github":"github.com/shuLhan", "site":"kilabit.info" } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Modules + go get
On Mon, 10 Sep 2018, 16:00 Paul Jolly, wrote: > > GO111MODULE=off go get -u github.com/my/package > Last time I check, if GOPATH is unset and GO111MODULE is on it will download the source code to $HOME/go. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Why can't we use unicode? [Go2 Generics]
> > Why on earth keep on ascii? > > IPA: ʅ ʧ ʭ (0x285, 0x2a7, 0x2ad) > Latin-E: « » ¦ > Latin-A: Ħ ŧ Ŧ Ɏ > Latin-B: ǁ ǂ > Probably because its hard to type on most non ASCII keyboard. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Listen by multiple goroutines via channels
On Mon, 3 Sep 2018 06:22:27 + Anik Hasibul wrote: > Can you please provide an example? I am new to golang. > Create N client receivers with channel and save the list of client channel as list, for x := 0; x < 5; x++ { cl := make(chan int, 1) chanClients = append(chanClients, cl) go clientReceiver(cl) } Then pass the main notification channel and list of client channels to master, and propagate notification to all client channels when data arrived, func masterReceiver(notif chan int, chanClients []chan int) { for n := range notif { for _, ch := range chanClients { ch <- n } } } -- { "github":"github.com/shuLhan", "site":"kilabit.info" } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] What am I missing here? FYI, I'm completely new to golang xD
On Mon, 3 Sep 2018, 13:03 'sebastian andersen' via golang-nuts, < golang-nuts@googlegroups.com> wrote: > This code want's me to believe that I have not declared any of the > variables that I am currently trying to declare: > > func deleteRow() { > db, err := sql.Open("mysql", "root@/testshit") > checkErr(err) > > // delete > stmt, err = db.Prepare("delete from userinfo where uid=?") > checkErr(err) > > res, err = stmt.Exec(id) > checkErr(err) > > affect, err = res.RowsAffected() > checkErr(err) > > fmt.Println(affect) > > db.Close() > } > You need to use short assignment ":=" for variable that is not declared previously. In your case, "stmt, err = ..." should be " stmt, err := ..." Tour about variable short assignment: https://tour.golang.org/basics/10 -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Listen by multiple goroutines via channels
On Mon, 3 Sep 2018, 13:03 , wrote: > I have a postgresql notification listener. > > And i have thousands of different goroutines. > > I am waiting to receive a single notification from each goroutine. > > > But only one channel is getting the value. Example: > https://play.golang.org/p/1a4cVLad8db > > > But I am expecting, all user `Receiver()` should receive all the values to > `ch` > > That's mean all user will get the value from `1` to `10` > > Any idea to achieve this? > The simple way to achieve this is using N master receiver that propagate value to all client receivers. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Re: How to setup your development environment using Go modules
On Fri, 31 Aug 2018 10:54:43 -0700 (PDT) Seth Hoenig wrote: > On Friday, August 31, 2018 at 12:22:28 PM UTC-5, Victor wrote: > > > > Hello everyone. I'm looking for best practices on how to setup your > > development environment using Go modules. > > > > Let assume a situation when you work on a project where you write a > > go package (call it Pkg) and an application (App) that uses that > > package Pkg and keep writing code in both. Using GOPATH, the > > process is pretty straightforward: you create your workspace, then > > you open $GOPATH/src/App project in your IDE and just continue > > editing .go files in both folders: $GOPATH/src/App and > > $GOPATH/src/Pkg where Pkg can be in a form " github.com/author/pkg" > > and that way in your App you can import it by the same > > "github.com/author/pkg" name and everything works since when you > > build App, it looks for that package in > > $GOPATH/src/github.com/author/pkg folder and always uses your > > latest changes. And since you have direct access to that folder in > > your IDE, you can continue editing Pkg while at the same time > > editing App. > > > > Now assume a situation where I want to get rid of GOPATH completely > > and start using modules. That way I'd put my App and Pkg folders in > > ~/Projects/App and ~/Projects/Pkg (since I don't have to put them > > in GOPATH any more). But then once App starts using go.mod file > > (assuming GO111MODULE is auto), it will be driven by > > "github.com/author/package" and store it in a local cache and not > > be using ~/Projects/Pkg where I make changes at the same time while > > working on ~/Projects/App. > > > > What would be the best practice to setup your development > > environment using Go modules? > > I am also stumbled on this issues, thanks for opening a topic on this. > > You'll want to add a replace directive to the go.mod file to > reference the copy of your library Pkg on disk, e.g. > > replace github.com/author/package => ..//package > This method does not work if someone clone the application repository manually using VCS. I am not sure is this by design or an issue. For example, here is the application with "replace" directive [1], master ms 0 % git clone https://github.com/shuLhan/rescached-go Cloning into 'rescached-go'... remote: Counting objects: 277, done. remote: Compressing objects: 100% (158/158), done. remote: Total 277 (delta 141), reused 234 (delta 98), pack-reused 0 Receiving objects: 100% (277/277), 264.64 KiB | 544.00 KiB/s, done. Resolving deltas: 100% (141/141), done. 6:19 ~/tmp master ms 0 % cd rescached-go 6:19 ~/tmp/rescached-go master ms 0 % git reset --hard 47c04cb4542505173a0216edffb5b8388838966f HEAD is now at 47c04cb make: fix typo on sudo 6:28 ~/tmp/rescached-go master ms 0 % cat go.mod module github.com/shuLhan/rescached-go require github.com/shuLhan/share v0.0.0-20180827221555-192454617153 replace github.com/shuLhan/share => ../share When I run go build, it will report error about missing module, 6:28 ~/tmp/rescached-go master ms 0 % go build ./... go: parsing ../share/go.mod: open /home/ms/tmp/share/go.mod: no such file or directory go: error loading module requirements If I remove the "replace" directive, Go can build the package. 6:31 ~/tmp/rescached-go master ms 0 % cat go.mod module github.com/shuLhan/rescached-go require github.com/shuLhan/share v0.0.0-20180827221555-192454617153 6:31 ~/tmp/rescached-go master ms 0 % go build ./... I think my problem is thinking that "replace" directive is optional, as in, If "replace" path not exist, use module from cache, otherwise get the required package from remote into cache.-- Shulhan because the syntax use relative import, not absolute import path. [1] https://github.com/shuLhan/rescached-go/commit/47c04cb4542505173a0216edffb5b8388838966f -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] [Bug?] Error when running "go tool cover" on package name contains dot
On Sun, 19 Aug 2018 16:13:00 -0700 (PDT) Dave Cheney wrote: > Point of clarification, the package name doesn’t contain a dot, that > is not permitted by the syntax of the package declaration. The name > of the directory you placed the file in ends in .go and this is > confusing the tool. > Sorry, I write a misleading words in previous message. I wrote "package name" where it should be "directory name". > If this is a regression from an earlier version of Go, please raise > an issue. > There is no problem when tested with Go v1.10.3. I will report it later, thank you for checking this. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] [Bug?] Error when running "go tool cover" on package name contains dot
Running "go tool cover" on package name contains dot with Go 1.11rc1 or latest dev on branch master return an error, but success on Go 1.10.3. Steps to reproduces - Create package name with dot ('.'). - Create minimal test file - Generate test coverage profile, go test -count=1 -coverprofile=cover.out ./... - Generate HTML coverage, go tool cover -html=cover.out -o cover.html Actual Result ``` 22:44 ~/tmp/sandbox/go/src/bug/gotoolcover.go master ms 1 % go version go version devel +bf80e3b564 Sat Aug 18 18:23:06 2018 + linux/amd64 22:44 ~/tmp/sandbox/go/src/bug/gotoolcover.go master ms 0 % go test -count=1 -coverprofile=cover.out ./... ok bug/gotoolcover.go 0.001s coverage: 0.0% of statements [no tests to run] 22:44 ~/tmp/sandbox/go/src/bug/gotoolcover.go master ms 0 % go tool cover -html=cover.out -o cover.html cover: cannot run go list: exit status 1 stat bug/gotoolcover.go: no such file or directory ``` Expected result Running on package name without dot, ``` 22:45 ~/tmp/sandbox/go/src/bug/gotoolcover-go master ms 0 % go version go version devel +bf80e3b564 Sat Aug 18 18:23:06 2018 + linux/amd64 22:45 ~/tmp/sandbox/go/src/bug/gotoolcover-go master ms 0 % go test -count=1 -coverprofile=cover.out ./... ok bug/gotoolcover-go 0.001s coverage: 0.0% of statements [no tests to run] 22:45 ~/tmp/sandbox/go/src/bug/gotoolcover-go master ms 0 % go tool cover -html=cover.out -o cover.html ``` Should I report this as an issue? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] [ANN] HAProxy log miner and forwarder
Hi all, I just like want to share a library and program written in Go to parse and forward HAProxy (UDP) stream log to Influxdb. https://github.com/shuLhan/haminer Have a nice day. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Possible bug on os.Stat and mode is symlink
Environment OS: Linux xenom-bubu 4.14.8-1-ARCH #1 SMP PREEMPT Wed Dec 20 21:27:44 UTC 2017 x86_64 GNU/Linux Go: go1.10beta1 linux/amd64 Steps to reproduce $ mkdir testSymlink $ cd testSymlink $ touch test $ ln -s test link $ cd .. $ test -L testSymlink/link # true, exit status 0 Test script bugSymlink.go, package main import ( "os" ) func main() { in := "testSymlink/link" fi, err := os.Stat(in) if err != nil { panic(err) } fileMode := fi.Mode() if fileMode != 0 { println(in, "is symbolic link") } else { println(in, "is not symbolic link") } } $ go run bugSymlink.go testSymlink/link is not symbolic link Is it a bug or I miss something? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Possible bug on os.Stat and mode is symlink
Environment OS: Linux xenom-bubu 4.14.8-1-ARCH #1 SMP PREEMPT Wed Dec 20 21:27:44 UTC 2017 x86_64 GNU/Linux Go: - go1.10beta1 linux/amd64 - go1.9.2 Steps to reproduce $ mkdir testSymlink $ cd testSymlink $ touch test $ ln -s test link $ cd .. $ test -L testSymlink/link # true, exit status 0 Test script bugSymlink.go, package main import ( "os" ) func main() { in := "testSymlink/link" fi, err := os.Stat(in) if err != nil { panic(err) } fileMode := fi.Mode() if fileMode != 0 { println(in, "is symbolic link") } else { println(in, "is not symbolic link") } } $ go run bugSymlink.go testSymlink/link is not symbolic link Is it a bug or I miss something? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] [ANN] gometalinter v2.0.0 released - much faster linting
On Mon, 4 Dec 2017 21:16:30 -0800 (PST) Alec Thomas <a...@swapoff.org> wrote: > Hello, > > Through the efforts of many contributors, and in particular those of > Daniel Nephin, v2.0.0 has been released. You can grab it here: > > https://github.com/alecthomas/gometalinter/releases/tag/v2.0.0 > On behalf of my team, I would like to say thank you for this project and to the maintainer of linter tools. Regards, Shulhan -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] acme, letsencrypt and different HTTPS ports
On Thu, 16 Nov 2017 20:59:16 -0800 (PST) Sankar <sankar.curios...@gmail.com> wrote: > Hi > > I have an EC2 vm where I want to run two go https servers on > different ports. > > I am using letsencrypt for the certificates and the code is like: > > server1.go: > log.Fatal(http.Serve(autocert.NewListener("api1.example.com"), > http.DefaultServeMux)) server2.go: > log.Fatal(http.Serve(autocert.NewListener("api2.example.com"), > http.DefaultServeMux)) > > I want api1 to listen on port 443 and want api2 to listed on port > 8080. Is it possible to achieve this via autocert at all ? If not, > are there any other hacks to get multiple ports exposed from the same > machine using letsencrypt ? I am deploying server1.go manually (via a > systemd script) and server2 via a docker container, if it matters. > > Any help ? > > Thanks. > Usually people use proxy in the front, and direct the traffic based on hostname. The proxy will listen on port 80 and 443 with valid certificate, and your backend is listened on other non root port (e.g. 9001 for api1 and 9002 for api2). Upon receiving the incoming connection proxy will check the hostname, if hostname is `api1.example.com`, proxy will forward the traffic to backend at port 9001. If hostname is `api2.example.com`, proxy will forward the traffic to backend at port 9002. Your server +--+ +-+ (1) +---+ | internet | <===> | proxy | <> | api1:9001 | +--+ +-++---+ ^^ || +---+ +> | api2:9002 | +---+ Some noticeable proxy application: haproxy. -- Shulhan -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Multiple Goroutine timeout
On Wed, 25 Oct 2017 06:30:09 -0700 (PDT) desaiabhi...@gmail.com wrote: > I am expecting to show url1 (2 sec ), url2 (4 sec ) but not url3( 6 > sec) where timeout is 5 sec > > but program showing only url1 value > > Please help > > https://play.golang.org/p/aMOoSEHjmZ > > Thanks in advance > > Rgds, > > Abhi > > > package main > > import "fmt" > import "time" > > func InvokeUrl1(u string, val chan<- string) { > time.Sleep(2 * time.Second) > val <- "Url1 Value" > } > func InvokeUrl2(u string, val chan<- string) { > time.Sleep(4 * time.Second) > val <- "Url2 Value" > } > func InvokeUrl3(u string, val chan<- string) { > time.Sleep(6 * time.Second) > val <- "Url3 Value" > } > > func GetUrlValues(urls []string) { > > ch := make(chan string, 1) > for _, url := range urls { > go func(u string) { > val := make(chan string) > if u == "url1" { > go InvokeUrl1(u, val) > } else if u == "url2" { > go InvokeUrl2(u, val) > } else if u == "url3" { > go InvokeUrl3(u, val) > } > > select { > case ret := <-val: > ch <- ret > case <-time.After(5 * time.Second): > ch <- "nil" > } > }(url) > } > fmt.Println(<-ch) You only print once, it suppose to be inside the loop or wrapped with select while <-ch != "nil". > } > func main() { > GetUrlValues([]string{"url1", "url2", "url3"}) > } > -- { "name":"Mhd Sulhan", "phone":"+628567826625", "site":"kilabit.info" } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] cannot assign 1 values to 2 variables [simple error handling]
On 18/09/17 10:00, Ângelo Chida wrote: Hi, I'm new in Golang but I'm PHP StackDev since 10 years ago I'm following this tutorial https://golang.org/doc/articles/wiki/ on how to build a web app, but I'm stuck on some error and can't find anywhere a solution. If you read down into "Data Structure" section, you will find the explanation for those function. > Functions can return multiple values. The standard library function |io.ReadFile|returns |[]byte|and |error|. In |loadPage|, error isn't being handled yet; the "blank identifier" represented by the underscore (|_|) symbol is used to throw away the error return value (in essence, assigning the value to nothing). > > But what happens if |ReadFile|encounters an error? For example, the file might not exist. We should not ignore such errors. Let's modify the function to return |*Page|and |error|. > > func loadPage(title string) (*Page, error) { > filename := title + ".txt" > body, err := ioutil.ReadFile(filename) > if err != nil { > return nil, err > } > return {Title: title, Body: body}, nil > } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] [ANN] j2p: A tool to help migrating from JIRA to Phabricator
Hi all, I would like to share a tool I made with Golang to help migrating from JIRA to Phabricator. It has been tested on our server, by migrating all projects and their issues, but have some limitations (due to time issue on development), - It does not migrate attachments - It does create sub-task (subtask will be created as task) If someone need and want to expand it, you can get the source code here: https://github.com/shuLhan/j2p -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: flag: Stack overflow when return stringer with fmt.Sprint
On Thursday, 1 September 2016 16:25:24 UTC+7, dja...@gmail.com wrote: > > Hi, > Do you know what infinite recursion is ? > Yes, I know. > fmt.String use your String method > > see https://play.golang.org/p/jeOilZW7JU > > By that logic, the first example should be stack overflow too, but it's not. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.