Re: [go-nuts] Re: Self Built Utility package cannot access variables beyond main

2025-06-10 Thread Zhaoxun Yan
t; On Jun 9, 2025, at 9:23 PM, Kurtis Rader wrote: > >  > On Mon, Jun 9, 2025 at 7:01 PM Zhaoxun Yan wrote: > >> Oh! Thank you Kurtis. So do you have a special Editor to inform you about >> the functions? My current editor cannot even tell what type of variable a >&g

Re: [go-nuts] Re: Self Built Utility package cannot access variables beyond main

2025-06-09 Thread Zhaoxun Yan
t 9:35 PM Zhaoxun Yan wrote: > >> it turned out to be an error misjudgement. The real line that caused >> trouble is this: >> s = er.Error()+string(out) >> The error is gone after I changed it to this line : >> s = fmt.Sprintf("%v %s", er, out) >>

[go-nuts] Re: Self Built Utility package cannot access variables beyond main

2025-06-08 Thread Zhaoxun Yan
it turned out to be an error misjudgement. The real line that caused trouble is this: s = er.Error()+string(out) The error is gone after I changed it to this line : s = fmt.Sprintf("%v %s", er, out) On Fri, Jun 6, 2025 at 6:29 PM Zhaoxun Yan wrote: > > pani

[go-nuts] Self Built Utility package cannot access variables beyond main

2025-06-06 Thread Zhaoxun Yan
panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x6646f2] goroutine 1 [running]: util.CommandArgs({0xc93cb0?, 0x2?, 0xc71380?}) /home/zxun/src/util/util.go:49 +0xf2 --

Re: [go-nuts] Spooky: http.Error(w, [text], [statusCode]) responds the code without the text

2025-05-27 Thread Zhaoxun Yan
representing what > you use, share the corrected version in a follow up. > > Hope that helps. > > Am Mo., 26. Mai 2025 um 10:48 Uhr schrieb Zhaoxun Yan < > yan.zhao...@gmail.com>: > >> Hi All! >> I am stuck with this bizarre phenomenon that the http.Error fun

[go-nuts] Spooky: http.Error(w, [text], [statusCode]) responds the code without the text

2025-05-26 Thread Zhaoxun Yan
Hi All! I am stuck with this bizarre phenomenon that the http.Error function does not repond with the customizable text defined by the second argument. Suppose a simple ill http server with this function that responds an error as always: -- func (con *Net) ServeHTTP(w ht

Re: [go-nuts] Is there a way to capture the error by "http.MaxBytesReader"?

2025-04-07 Thread Zhaoxun Yan
Thanks a lot Olly! I tried to do some research, here is my code, does it look OK? ``` r.Body = http.MaxBytesReader(w, r.Body, con.SizeLimit) defer r.Body.Close() _, err := io.Copy(ioutil.Discard, r.Body) if err != nil { ip := r.Header.Get("X-Real-Ip") fmt.Println("someone just send

[go-nuts] Is there a way to capture the error by "http.MaxBytesReader"?

2025-04-04 Thread Zhaoxun Yan
It used to send an error response to the client with code 405, with log info like this: reverseproxy.go:476: http: proxy error: readfrom tcp 127.0.0.1:35064->127.0.0.1:8006: http: request body too large but I want to analyze the header and capture "X-Real-IP" of the client so as it happens con

[go-nuts] Re: “Normal” vs. “error” (control flow) is a fundamental semantic distinction

2022-05-25 Thread Zhaoxun Yan
Try & Catch sounds great! 在2022年5月19日星期四 UTC+8 00:15:09 写道: > Hi all, > > I thought now was the time to go public. The automatic error propagation > is possible with the help of a simple Go package, and it has been about > three years now: > > func CopyFile(src, dst string) (err error) { >

Fwd: [go-nuts] Improving safe global variables with generic or inheritance

2022-05-23 Thread Zhaoxun Yan
-- Forwarded message - From: Zhaoxun Yan Date: Mon, May 23, 2022 at 6:05 PM Subject: Re: [go-nuts] Improving safe global variables with generic or inheritance To: Brian Candler *That's really essential. For example, using your library, the following code is most definitely

Re: [go-nuts] Improving safe global variables with generic or inheritance

2022-05-23 Thread Zhaoxun Yan
`&` won't make any difference: undefined: atomic.Int32 On Mon, May 23, 2022 at 4:31 PM Axel Wagner wrote: > On Mon, May 23, 2022 at 10:19 AM Zhaoxun Yan > wrote: > >> Yes but the syntax is confusing, e.g. the code below fails: >> > > That's bec

Re: [go-nuts] Improving safe global variables with generic or inheritance

2022-05-23 Thread Zhaoxun Yan
e you aware of the sync/atomic package? >>> https://pkg.go.dev/sync/atomic >>> There are also some changes in there for Go 1.18, specifically the >>> addition of some types, so that only atomic operations can be done: >>> https://pkg.go.dev/sync/atomic@master >

Re: [go-nuts] Improving safe global variables with generic or inheritance

2022-05-23 Thread Zhaoxun Yan
ly atomic operations can be done: > https://pkg.go.dev/sync/atomic@master > I mention this because atomic.Value and atomic.Pointer[T] are essentially > what you are suggesting here. > > On Mon, May 23, 2022 at 8:04 AM Zhaoxun Yan wrote: > >> However, as I want to narrow th

[go-nuts] Improving safe global variables with generic or inheritance

2022-05-22 Thread Zhaoxun Yan
Hi gophers! In the last post I proposed a way to avoid I/O race on any global variable: https://groups.google.com/g/golang-nuts/c/4AW1Ss9Tjp0 However, the code does not seem tidy, since each type needs to repeat defining the two methods Save and Load, though using this methods is easy. So I di

Re: [go-nuts] Re: DeepCloning a datastructure

2022-05-06 Thread Zhaoxun Yan
Yes there are two open source packages regarding "DeepCopy" https://github.com/mohae/deepcopy/ https://github.com/barkimedes/go-deepcopy/ Has anyone tried them yet? 在2020年4月19日星期日 UTC+8 01:26:11 写道: > How about doing it manually? You can define a DeepCopy method on the type > and manually allo

Re: [go-nuts] Re: A patch to avoid point-time race coincidence like Rust

2022-05-05 Thread Zhaoxun Yan
4 PM Kurtis Rader wrote: > On Thu, May 5, 2022 at 8:50 PM Zhaoxun Yan wrote: > >> Hi Kurtis! >> Thanks for your reply. >> >> I am just stating the fact that atomic module did not solve the reading >> writing conflict as it may sound so, or Brian perceived so. &

Re: [go-nuts] Re: A patch to avoid point-time race coincidence like Rust

2022-05-05 Thread Zhaoxun Yan
telive/ctpschedule.go:424 +0xbc main.main() /home/zxun/src/quotelive/main.go:56 +0x251 == On Fri, May 6, 2022 at 11:25 AM Kurtis Rader wrote: > On Thu, May 5, 2022 at 7:50 PM Zhaoxun Yan wrote: > >> I already know that a copy of map does not make a difference. That is why >&

Re: [go-nuts] Re: A patch to avoid point-time race coincidence like Rust

2022-05-05 Thread Zhaoxun Yan
I already know that a copy of map does not make a difference. That is why I put it inside a struct, but magic did not happen. Does the sync.Map solves reading and writing conflict? For I checked the print out log and discovered that even `atomic` module did not prevent such race warnings. There a

Re: [go-nuts] Re: A patch to avoid point-time race coincidence like Rust

2022-05-05 Thread Zhaoxun Yan
Hi Brian! I just checked my previous code for race errors. It turned out that a `map` is very hard to avoid the race condition. I have already put reading and writing into different functions with a global lock. The reading basically sends the struct wrapped map to a channel. Then there is anoth

[go-nuts] A patch to avoid point-time race coincidence like Rust

2022-04-30 Thread Zhaoxun Yan
A global variable has a plausible chance to race as one goroutine reads it while another writes it, as shown in previous post: https://groups.google.com/g/golang-nuts/c/PHw_zU6Ayfo So I am trying to enforce a lock on each global variable to avoid such accident just as Rust does on every variabl

Re: [go-nuts] go fails to detect a point-time race condition

2022-04-30 Thread Zhaoxun Yan
variable is from a crontask. They have a possibility to collide, but my race build did not crash because of it yet. Zhaoxun 在2022年5月1日星期日 UTC+8 00:18:11 写道: > * Zhaoxun Yan [220430 02:29]: > > Hi Dan! > > > > I did as you told, but go build -race still not functions: >

Re: [go-nuts] go fails to detect a point-time race condition

2022-04-29 Thread Zhaoxun Yan
() /home/zxun/src/race2/race.go:19 +0x38 Goroutine 7 (running) created at: main.main() /home/zxun/src/race2/race.go:17 +0x4f == 5 Found 1 data race(s) exit status 66 在2022年4月30日星期六 UTC+8 14:22:26 写道: > On Fri, 2022-04-29 at 23:18 -0700, Zhaoxun Yan wrote: > > And the

Re: [go-nuts] go fails to detect a point-time race condition

2022-04-29 Thread Zhaoxun Yan
> > > Goroutine 7 (running) created at: > main.main() > /home/zxun/src/race.go:17 +0x4f > == > 5 > Found 1 data race(s) > > Do you know the syntax to detect race condition for a whole folder of > codes, instead of one file? > Thanks.

Re: [go-nuts] go fails to detect a point-time race condition

2022-04-29 Thread Zhaoxun Yan
4月30日星期六 UTC+8 14:05:45 写道: > On Sat, Apr 30, 2022 at 7:49 AM Zhaoxun Yan wrote: > >> Point-time race condition is undetectable by `go build race`. >> > > When I run your code using `go run -race`, it reports a data race: > >> >> == >>

[go-nuts] Re: go fails to detect a point-time race condition

2022-04-29 Thread Zhaoxun Yan
package main import "time" import "fmt" var index int64 func increase(){ index++ } func read(){ fmt.Println(index) } func main(){ go func(N int){ for i:=0; i < N; i++{ increase() time.Sleep(500 * time.Millisecond) } }(5) time.Sleep(2 * time.Second) read

[go-nuts] go fails to detect a point-time race condition

2022-04-29 Thread Zhaoxun Yan
point race means I/O on a global might clash at certain point of time. consider this example: package main import "time" import "fmt" var index int64 func increase(){ index++ } func read(){ fmt.Println(index) } func main(){ go func(N){ for i:=0; i < N; i++{ increase()

Re: [go-nuts] Re: Protective buffered channel that never triggers deadlock

2022-04-20 Thread Zhaoxun Yan
" Strangely I found the start testing and disconnect log clustered and the disconnect did actually happen. Then I switch back to the sequential case that the receiving channel gots filled without receiving until disconnection. It works now." -- I found the error occurred again. It turned out that

Re: [go-nuts] Any recipe to stop a goroutine of a function other than of a channel?

2022-04-16 Thread Zhaoxun Yan
given up, but can still be a useful technique in some circumstances. > > Hope this helps, > rog. > > On Sat, 16 Apr 2022, 14:30 Zhaoxun Yan, wrote: > >> Timeout is quite common practice in programming. For example, Listen >> function in internet connection wit

[go-nuts] Any recipe to stop a goroutine of a function other than of a channel?

2022-04-16 Thread Zhaoxun Yan
Timeout is quite common practice in programming. For example, Listen function in internet connection with a timeout may just close the connection and Listen thread as silence persists for some period, like 60 seconds. I found it very hard to implement such a general shutdown feature of a thr

[go-nuts] Re: MatrixOne: a hyperconverged and one-size-fits-most database in Go

2022-04-16 Thread Zhaoxun Yan
Does it support sequence and upsert in PostgreSQL? 在2022年4月16日星期六 UTC+8 00:47:48 写道: > Hi, > > I’d like to introduce a hyperconverged and one-size-fits-most database > named MatrixOne, written in Go. > > Github: https://github.com/matrixorigin/matrixone > > It’s a redesigned database with a com

Re: [go-nuts] Re: Protective buffered channel that never triggers deadlock

2022-04-15 Thread Zhaoxun Yan
Thanks for your demonstration, Brian. Actually my code involving cgo is quite like your first case, like this code: *log("start testing")* *go func{* * for* * select* * case a: <=receiving* * case <- killsig* *...* *}()* *subscribequotations* *( meanwhile the cgo of the dll will c

[go-nuts] Re: Protective buffered channel that never triggers deadlock

2022-04-14 Thread Zhaoxun Yan
This code really blows my mind, Brian! I didn't know select can be flexible as this: package main import ( "fmt" ) var Ch = make(chan int, 1) func Fill(ch chan int, k int) { select { case ch <- k: // sent default: // discard } } func main() { fmt.Print

Re: [go-nuts] Tool to check binaries for vulnerabilities

2022-04-14 Thread Zhaoxun Yan
That sounds great! Thanks. 在2022年4月15日星期五 UTC+8 05:55:27 写道: > On Thu, 2022-04-14 at 03:05 -0700, Michel Casabianca wrote: > > Any comment and contribution welcome. > > Can I suggest that you use golang.org/x/sys/execabs rather than os/exec > in ExecCommand? > > > -- You received this message b

[go-nuts] Re: generics: parametric types unmarshaling

2022-04-14 Thread Zhaoxun Yan
Here is my note on json & struct, run it somewhere and it may give you a hint. package main import "fmt" import "encoding/json" type prices struct{ Price float64 `json:"price"` floor float64 Ceiling float64 settle float64 timeint64 } func main() { content := p

Re: [go-nuts] Re: Protective buffered channel that never triggers deadlock

2022-04-14 Thread Zhaoxun Yan
Something bizarre happened in CGO. My new code started the anonymous goroutine to receive first but it does not sleep below the goroutine and jumps to end the function. So I returned to the sending before receiving way, which guaranteed the program's safety. There ain't always one way that fits a

Re: [go-nuts] Re: Protective buffered channel that never triggers deadlock

2022-04-13 Thread Zhaoxun Yan
You are right, Brian. The difference is not whether the channel is buffered or unbuffered - while the receiver is present, none will encounter the deadlock. package main import ( "fmt" "time" ) //var c = make(chan int) var c = make(chan int, 2) func report(){ for{ select

[go-nuts] Protective buffered channel that never triggers deadlock

2022-04-13 Thread Zhaoxun Yan
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 goro

[go-nuts] Re: Why Go has only slice and map

2022-04-13 Thread Zhaoxun Yan
https://github.com/Workiva/go-datastructures Are they available in the current version of go? 在2022年4月12日星期二 UTC+8 23:21:20 写道: > I'm certainly not privy to the nitty-gritty, but I'd encourage you to skim > over the Go Dev team meeting notes. It's really cool to see what people > have propose

Re: [go-nuts] encoding/json mistakenly transfer int64 format to string

2022-04-12 Thread Zhaoxun Yan
re ignoring error from json.Marshal which could be > hiding a problem, so I would recommend you handle that. > > encoding/json should represent float as a json number so I would never > expect what you're seeing but its not clear to me if that is down to how > you are viewing i

Re: [go-nuts] Hesitating on using cached / un-cached channels

2022-04-12 Thread Zhaoxun Yan
annot run until the second > case is done, which will terminate the loop. > > On Mon, Apr 11, 2022 at 10:08 PM robert engels > wrote: > >> There are numerous ways to create a “dead lock” in any program (this may >> actually be a “live lock” but I didn’t fully underst

[go-nuts] Re: Is it possible to change the existing printline dynamically in golang?

2022-04-11 Thread Zhaoxun Yan
Thanks a log Amnon! :D 在2022年4月1日星期五 UTC+8 21:25:14 写道: > Yes, this is the murky world of ANSI escape codes. > Fortunately there are a whole load of libraries which do this for you... > Try https://github.com/cheggaaa/pb > or https://github.com/schollz/progressbar > or github.com/vardius/progress

[go-nuts] encoding/json mistakenly transfer int64 format to string

2022-04-11 Thread Zhaoxun Yan
The scenario is upon receiving an incoming financial quotation, save it as a string of json into a Redis service. Sorry but I cannot provide the whole code of quotation receiving here, which is very complex with cgo. But the code below will help you get a glimpse on what should be going on: imp

[go-nuts] Hesitating on using cached / un-cached channels

2022-04-11 Thread Zhaoxun Yan
Hi guys, I have a great demonstration on why an un-cached channel might malfunction while receiving: package main import( "fmt" "time" ) func main(){ t := time.NewTicker(time.Second * 3) stopnow := make(chan bool) //stopnow := make(chan bool, 1) //cached channel instead

[go-nuts] Re: Is it possible to change the existing printline dynamically in golang?

2022-04-01 Thread Zhaoxun Yan
Got it: package main import( "fmt" "time" ) func main() { fmt.Printf("Hello") time.Sleep(time.Second) time.Sleep(time.Second) fmt.Printf("\r") fmt.Printf("World\n") } 在2022年4月1日星期五 UTC+8 15:34:08 写道: > You can use the ansi escape code if the target terminal supports it.

Re: [go-nuts] Why is it forbidden to add methods to an existing type?

2022-03-31 Thread Zhaoxun Yan
via inheritance. Since Go >> does not have inheritance, you can achieve a similar effect with standalone >> functions. >> >> On Friday, March 18, 2022 at 11:26:51 AM UTC+7 Ian Lance Taylor wrote: >> >>> On Thu, Mar 17, 2022 at 7:17 PM Zhaoxun Yan wrote:

[go-nuts] Is it possible to change the existing printline dynamically in golang?

2022-03-31 Thread Zhaoxun Yan
I just noticed how python pip upgraded from printing numerous process bars like this: ■■■ 30% completed 40% completed ■■60% completed 80% completed ■■ 100% completed to a single line of a growing bar and changing decla

Re: [go-nuts] how to protect source code

2022-03-17 Thread Zhaoxun Yan
I think it is best to run your code on an encrypted disk. So it cannot be stolen by taking away the hard-drive. Furthermore if the config and log files are in other folders, it is okay to shut down the encrypted drive I guess. In that case even it is running in memory, the hacker cannot get acces

[go-nuts] Why is it forbidden to add methods to an existing type?

2022-03-17 Thread Zhaoxun Yan
Hi everyone! I just came across this taboo in golang - new methods cannot be added to an existing type: package main import "fmt" func (s string) print(){ fmt.Println(s) } func main() { "hello, world\n".print() } --Error ./main.go:5: cannot define new methods on non-local

[go-nuts] Is the disconnection synchronization solid in gorilla/websocket?

2022-03-16 Thread Zhaoxun Yan
Since read and send messages are in different functions/goroutines, when an error occurs, how can they be synchronized? Suppose I set up a listen goroutine by this function below, with `conn` as a global variable of the connection: func listen(){ for{ _, message, err := conn.ReadMessa

Re: [go-nuts] Is there a way to syncronise map reads and writes?

2022-02-23 Thread Zhaoxun Yan
t; On Tuesday, February 22, 2022 at 9:55:04 PM UTC-6 ren...@ix.netcom.com >> wrote: >> >>> Something else is wrong - because marketMaps is read-only after init… so >>> unless you have some other code - that is not the map causing the panic. >>> >>> My gues

Re: [go-nuts] Is there a way to syncronise map reads and writes?

2022-02-23 Thread Zhaoxun Yan
Hi Brian, thanks for replying! So you mean that I have to use 5 Mutexes for Market data of each one source ? That is exactly what I want to do. Every action of RW marketMap[i] must comes in one line, but RW marketMap[j] concurrently is allowed. And mapLocks now is fine in golang? The reason why I

Re: [go-nuts] Is there a way to syncronise map reads and writes?

2022-02-23 Thread Zhaoxun Yan
ultiple threads outside the lock (the map > is a reference not a copy) and that is causing the panic. > > On Feb 22, 2022, at 9:39 PM, Zhaoxun Yan wrote: > > Hi guys! > I know this is quite challenging, but it makes sense in io-heavy > applications. > > I need to test the re

[go-nuts] Is there a way to syncronise map reads and writes?

2022-02-22 Thread Zhaoxun Yan
Hi guys! I know this is quite challenging, but it makes sense in io-heavy applications. I need to test the responsiveness of different financial future quotation sources. They return the quotations spontaneously, and my program respond to each one of the CGO call backs from the quotation librar

[go-nuts] What goes wrong when embedding goroutines inside a for loop?

2022-02-17 Thread Zhaoxun Yan
package main import "fmt" func main() { targetIndice := make([]int, 3) targetIndice[0] = 5 targetIndice[2] = 4 for i,n := range targetIndice{ fmt.Printf("%d : %d \n", i, n) } c := make(chan int) for i, n:= range targetIndice{ go func(){