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] 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] 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] 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.
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.
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] 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] 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] 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.