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
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)
>>
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
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
--
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
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
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
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
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) {
>
-- 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
`&` 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
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
>
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
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
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
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.
&
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
>&
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
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
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
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:
>
()
/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
>
>
> 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.
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:
>
>>
>> ==
>>
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
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()
" 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
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
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
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
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
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
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
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
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
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
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
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 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
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
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
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
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
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.
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:
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
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
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
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
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
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
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
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
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(){
54 matches
Mail list logo