Re: [go-nuts] Where is my type?

2024-04-24 Thread burak serdar
In the first case, the interface contains a value of type S, which is not writable. The value contained in the interface is not addressable. So Unmarshal creates a new map and fills that. In the second case the interface contains *S, which is writable, so unmarshal fills it in via reflection. On

Re: [go-nuts] Re: xml to json, parsing xml

2024-04-23 Thread burak serdar
In general, you cannot convert xml to json. They have incompatible models. XML elements are ordered similar to a JSON array, but in many cases you want to map XML elements to JSON objects, which are unordered name-value collections. Also, there is no JSON equivalent of an XML attribute. If you

Re: [go-nuts] Why can't I use an interface which needs another interface inside of it

2024-03-13 Thread burak serdar
On Wed, Mar 13, 2024 at 10:31 AM Rodrigo Araujo wrote: > > Do you mean b.GetChilder? In this case, package A will depend on package B > and I don't think this is a good approach. Why would it not be a good approach? You have a package declaring interfaces, and if you have another package using

Re: [go-nuts] How to have a raw parameter value in cobra?

2024-02-25 Thread burak serdar
nothing else. > > On Sunday, February 25, 2024 at 10:52:10 AM UTC-8 burak serdar wrote: >> >> You can do rootCmd.SetArgs(os.Args[2:]), and process the first >> parameter yourself. >> >> On Sun, Feb 25, 2024 at 11:43 AM David Karr wrote: >> > >> >

Re: [go-nuts] How to have a raw parameter value in cobra?

2024-02-25 Thread burak serdar
You can do rootCmd.SetArgs(os.Args[2:]), and process the first parameter yourself. On Sun, Feb 25, 2024 at 11:43 AM David Karr wrote: > > I am not a new programmer, but I am pretty new to golang, having only written > a couple of small applications, and that was several months ago. I'm trying

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-22 Thread burak serdar
On Thu, Feb 22, 2024 at 10:39 AM Axel Wagner wrote: > > > > On Thu, Feb 22, 2024 at 6:06 PM burak serdar wrote: >> >> I don't think this case really applies here. I get that comparison of >> a==b may or may not be true. The problem is that if a==b at some po

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-22 Thread burak serdar
t; >> I see. Sorry, I was jumping to conclusions and didn't quite get what you >> mean. That is my fault. >> >> I agree that this looks confusing and is arguably a bug. I filed >> https://github.com/golang/go/issues/65878, thanks for pointing it out. >> &g

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-22 Thread burak serdar
But apart from > that, who knows. > > Zero-sized variables *may* have the same address. They don't *have* to. > > On Thu, Feb 22, 2024 at 5:12 PM burak serdar wrote: >> >> On Thu, Feb 22, 2024 at 9:00 AM Axel Wagner >> wrote: >> > >> > Note that i

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-22 Thread burak serdar
and the other is not. > > On Thu, Feb 22, 2024 at 4:53 PM burak serdar wrote: >> >> The compiler can allocate the same address for empty structs, so I >> actually expected a==b to be true, not false. However, there's >> something more interesting going on here because: &

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-22 Thread burak serdar
The compiler can allocate the same address for empty structs, so I actually expected a==b to be true, not false. However, there's something more interesting going on here because: a := {} b := {} fmt.Printf("%t\n", *a == *b) fmt.Printf("%t\n", a == b) fmt.Printf("%p %p\n", a, b) x := Bar(a) y :=

Re: [go-nuts] Is there a way to cast interface to embedded type?

2024-02-09 Thread burak serdar
On Fri, Feb 9, 2024 at 1:37 PM Christopher C wrote: > > I have a base struct that implements an interface. There are multiple other > structs that embed this base struct. I would like to pass the an interface > into a function that can cast it as the base struct and call some functions > tied

Re: [go-nuts] Incorrect "missing return" error for an edge case

2024-01-08 Thread burak serdar
body - in particular, if you want to do it on a purely > > syntactical level). > > It also also can be replaced by `func TestMethod() int { return 0 }`, > > which is strictly better, more readable code, so I wouldn't even > > necessarily agree that it's a false-positive e

[go-nuts] Incorrect "missing return" error for an edge case

2024-01-07 Thread burak serdar
This question came up on Stack Overflow today: The following code is giving a "missing return" error where it shouldn't: func TestMethod() int { for i := 0; i < 10; i++ { return 0 } } Looks like an overlooked case in control flow analysis. -- You received this message because you

Re: [go-nuts] Go type assertion for MongoDB []bson.M{}/primitive.A type

2023-11-16 Thread burak serdar
imitive.A)[0] > var a1 author > bson.Unmarshal(r.([]byte), ) > a = append(a, a1) > > I'm getting: > > panic: interface conversion: interface {} is primitive.M, not []uint8 > > > On Thursday, November 16, 2023 at 12:20:13 PM UTC-5 burak serdar wrote: > > val[&q

Re: [go-nuts] Go type assertion for MongoDB []bson.M{}/primitive.A type

2023-11-16 Thread burak serdar
val["author"].(primitive.A)[0] is correct, but the type of that expression is not author, it is bson.M. You might consider using a tagged struct to unmarshal this. On Thu, Nov 16, 2023 at 10:11 AM Tong Sun wrote: > > Further on with the question >

Re: [go-nuts] Re: Is "When in doubt, use a pointer receiver" misleading advice?

2023-11-14 Thread burak serdar
it, or by inlining the version function, but according to the spec, it is passed by value, i.e., it is copied. On Tue, Nov 14, 2023 at 4:16 PM burak serdar wrote: > > It is a data race because calling rpc.version() makes a copy of rpc, > which causes reading the field rpc.result concurren

Re: [go-nuts] Re: Is "When in doubt, use a pointer receiver" misleading advice?

2023-11-14 Thread burak serdar
It is a data race because calling rpc.version() makes a copy of rpc, which causes reading the field rpc.result concurrently while it is being written by the goroutine. On Tue, Nov 14, 2023 at 3:59 PM Mike Schinkel wrote: > > On Monday, November 13, 2023 at 11:28:00 PM UTC-5 Dan Kortschak wrote:

Re: [go-nuts] When to share an interface, and when not to.

2023-09-26 Thread burak serdar
On Tue, Sep 26, 2023 at 6:18 AM Jerry Londergaard wrote: > > > Do I need to be re-defining this interface everywhere? I guess > an alternative would be to just re-use the `C.DoThinger`, but I feel like > this doesn't seem right as now A is directly importing C, which seems to > 'break' the

Re: [go-nuts] Ensure context timeout behaviour from caller, or callee ?

2023-09-20 Thread burak serdar
outines, and > passing down the context, > and the code being run in those goroutines isn't listening for cancellation > signals, > which results in the running goroutine becoming leaked, then that feels like > a bug in that code (i.e not the callers responsibility). >

Re: [go-nuts] Ensure context timeout behaviour from caller, or callee ?

2023-09-20 Thread burak serdar
On Wed, Sep 20, 2023 at 7:47 AM Jerry Londergaard wrote: > > When using a context.WithTimeout, I always felt that it should be the > function where the context was created should be the one that ensures that it > (the current function) does not block longer than intended. That is to say, > it

Re: [go-nuts] Download large Zip file via sftp

2023-08-23 Thread burak serdar
On Wed, Aug 23, 2023 at 6:37 AM Phillip Siessl wrote: > Hi > > i have some issues when i try to download a larger zip file (5GB) via the > sftp package in go. > about 20% of the time it runs through smoothly but the other 80% i get a > panic with > "fatal error: concurrent map writes writing to

Re: [go-nuts] Is atomic.CompareAndSwap a read-aquire (even if it returns false)?

2023-08-20 Thread burak serdar
Based on the following description in the memory model, CAS counts as a read: "Some memory operations are read-like, including read, atomic read, mutex lock, and channel receive. Other memory operations are write-like, including write, atomic write, mutex unlock, channel send, and channel close.

Re: [go-nuts] Best IDE for GO ?

2023-08-20 Thread burak serdar
On Sun, Aug 20, 2023 at 1:52 AM TheDiveO wrote: > well, our "(major) engineering orgs" leave the choice of IDE to our devs. > Devs have different styles, so as long as they meed the demand, who cares. > I second that. IDE is a personal choice. For years, I've been using Emacs to edit code, and

Re: [go-nuts] Clarification on code snippet

2023-08-04 Thread burak serdar
On Fri, Aug 4, 2023 at 10:33 AM alchemist vk wrote: > Hi folks, > In below code, I am invoking receiver api show() via a simple uInteger > type variable instead of pointer, by which it expects to be invoked . Go > being strict with type casing and I was expecting a compiler error. But to > my

Re: [go-nuts] Hard-to-explain race detector report

2023-06-08 Thread burak serdar
On Wed, Jun 7, 2023 at 2:19 PM Sven Anderson wrote: > > > Caleb Spare schrieb am Mi. 7. Juni 2023 um 19:22: > >> On Wed, Jun 7, 2023 at 2:33 AM Sven Anderson wrote: >> > >> > That’s not only a read/write race, it’s also a write/write race. Every >> request to the server creates a new Go

Re: [go-nuts] Hard-to-explain race detector report

2023-06-07 Thread burak serdar
On Wed, Jun 7, 2023, 12:33 PM Sven Anderson wrote: > That’s not only a read/write race, it’s also a write/write race. Every > request to the server creates a new Go routine that might increment > newConns in parallel, so it may get corrupted. Same for lines 39/40. > The write/write race will

Re: [go-nuts] Hard-to-explain race detector report

2023-06-07 Thread burak serdar
On Tue, Jun 6, 2023 at 5:31 PM Caleb Spare wrote: > Can someone explain why the following test shows a race between the > indicated lines? > > > https://github.com/cespare/misc/blob/b2e201dfbe36504c88e521e02bc5d8fbb04a4532/httprace/httprace_test.go#L12-L43 > > The race seems to be triggered by

Re: [go-nuts] Re: Amateur's questions about "Go lang spec"

2023-06-03 Thread burak serdar
On Sat, Jun 3, 2023 at 1:40 PM peterGo wrote: > > Kamil Ziemian, > > // list of prime numbers > primes := []int{2, 3, 5, 7, 9, 2147483647} > > The variable prime is a list of some prime numbers starting with the > lowest and ending with the highest prime numbers that can safely be > represented

Re: [go-nuts] Using struct{} for context keys

2023-05-28 Thread burak serdar
Two values A and B are equal (A==B) if A and B have the same type and the same values. In a code where a:=clientContextKey{} b:=clientContextKey{} a==b is true, because they have the same types, and they have the same values (i.e. the empty value). Note however: a:={} b:={} It is not

Re: [go-nuts] Experience with building JS and Python bindings for a Go library

2023-05-22 Thread burak serdar
On Mon, May 22, 2023 at 6:35 PM Taco de Wolff wrote: > I would like to know if anyone has experience with building bindings for > JavaScript (NodeJS) and Python for a Go library. Who has worked on this, or > does anybody know of libraries that have succeeded? > I used the following two

Re: [go-nuts] Immediately Cancel Goroutine?

2023-04-12 Thread burak serdar
On Wed, Apr 12, 2023 at 7:29 AM Frank wrote: > Hi Gophers, > > So I've run into a situation where my code would run for a rather long > time (10minutes - ~1 hour). And I want to cancel it halfway sometimes. I > know I can use channel/context can check for channel message to return > early. But

Re: [go-nuts] Map of Types is impossible, is there any alternative solution?

2023-04-11 Thread burak serdar
You can do: var messageProcessors = map[uint8]func([]byte) Message { 0: processorForType0, 1: processorForType1, ... } Then: output:=messageProcessors[id](payload) Of course, with the appropriate error checks. On Tue, Apr 11, 2023 at 3:13 PM Bèrto ëd Sèra wrote: > I do know there's no

Re: [go-nuts] Interesting "select" examples

2023-04-03 Thread burak serdar
Below is part of a generic ordered fan-in for data pipelines. It works by reading data from multiple channels using one goroutine for each channel, sending that data element to another goroutine that does the actual ordering, but in the mean time, pauses the pipeline stage until all out-of-order

Re: [go-nuts] HTTP client - streaming POST body?

2023-03-22 Thread burak serdar
On Wed, Mar 22, 2023 at 8:32 PM 'Christian Stewart' via golang-nuts < golang-nuts@googlegroups.com> wrote: > you can achieve this using an io.Pipe. The io.Pipe function returns a > connected pair of *PipeReader and *PipeWriter, where writes to the > *PipeWriter are directly read from the

Re: [go-nuts] Why can't a regexp.Regexp be const

2023-02-13 Thread burak serdar
This compiles just fine, but the regexp compilation fails: https://go.dev/play/p/QvC8CIITUU6 On Mon, Feb 13, 2023 at 4:49 PM Pat Farrell wrote: > This won't compile > > var ExtRegex = > regexp.MustCompile("(M|m)(p|P)(3|4))|((F|f)(L|l)(A|a)(C|c))$") > > with a > ./prog.go:10:18: >

Re: [go-nuts] Upgradable RLock

2023-01-29 Thread burak serdar
On Sun, Jan 29, 2023 at 7:34 PM Diego Augusto Molina < diegoaugustomol...@gmail.com> wrote: > From times to times I write a scraper or some other tool that would > authenticate to a service and then use the auth result to do stuff > concurrently. But when auth expires, I need to synchronize all

Re: [go-nuts] Clarification of memory model behavior within a single goroutine

2023-01-21 Thread burak serdar
On Sat, Jan 21, 2023 at 12:11 PM Peter Rabbitson (ribasushi) < ribasu...@gmail.com> wrote: > On Saturday, January 21, 2023 at 7:48:12 PM UTC+1 bse...@computer.org > wrote: > On Sat, Jan 21, 2023 at 10:36 AM Peter Rabbitson > wrote: > Greetings, > > I am trying to understand the exact mechanics

Re: [go-nuts] Clarification of memory model behavior within a single goroutine

2023-01-21 Thread burak serdar
On Sat, Jan 21, 2023 at 10:36 AM Peter Rabbitson wrote: > Greetings, > > I am trying to understand the exact mechanics of memory write ordering > from within the same goroutine. I wrote a self-contained runnable example > with the question inlined here: https://go.dev/play/p/ZXMg_Qq3ygF and am >

Re: [go-nuts] Simple Regexp fails but more complex one finds match

2023-01-19 Thread burak serdar
This: (-)* matches the empty string as well, and that's what it is returning. Try (-)+ On Thu, Jan 19, 2023 at 12:16 PM Pat Farrell wrote: > This has to be something simple, but I've been pulling my hair out for > days. > I have made two regexp.MustCompile where one is just a simple

Re: [go-nuts] Go 1.19 comparison of variables of generic type

2023-01-18 Thread burak serdar
On Wed, Jan 18, 2023 at 5:52 PM Andrew Athan wrote: > (Possibly related to issues such as those discussed in > https://groups.google.com/g/golang-nuts/c/pO2sclKEoQs/m/5JYjveKgCQAJ ?) > > If I do: > > ``` > func Foo[V any](v V)bool { > return v==v > } > ``` > > golang 1.19 reports: > > ``` >

Re: [go-nuts] Re: Why not tuples?

2022-12-03 Thread burak serdar
On Sat, Dec 3, 2022 at 8:47 PM Diogo Baeder wrote: > Hi there, sorry for weighting in so late in the game, but I just started > again to learn Go and was thinking why the language still doesn't have a > tuple type. > > Now, imagine this scenario: I have a web application which has to access a >

Re: [go-nuts] Performance for concurrent requests

2022-12-02 Thread burak serdar
On Fri, Dec 2, 2022 at 8:13 PM Diogo Baeder wrote: > Hi guys, > > I've been working on some experiments with different web application > stacks to check their performances under a specific scenario: one in which > I have to make several concurrent requests and then gather the results > together

Re: [go-nuts] Go Memory Model question

2022-12-02 Thread burak serdar
The way I read the memory model, this program can print 01, 00, and 11, but not 10. This is because goroutine creation creates a synchronized before relationship between x=1 and x=0, so even though there is a race, x=0 happens before x=1. On Fri, Dec 2, 2022 at 6:56 AM のびしー wrote: > > I believe

Re: [go-nuts] How to fix an awful marshal reflection hack

2022-12-01 Thread burak serdar
On Thu, Dec 1, 2022 at 6:39 AM 'Mark' via golang-nuts < golang-nuts@googlegroups.com> wrote: > The reason there's no nullable in the real code is that it isn't needed > there: if the field is to a pointer variable (e.g., *string), then I call > hack() and that adds the '?' to the string so no

Re: [go-nuts] How to fix an awful marshal reflection hack

2022-11-30 Thread burak serdar
On Wed, Nov 30, 2022 at 10:17 AM 'Mark' via golang-nuts < golang-nuts@googlegroups.com> wrote: > Yes, I'd already tried that (that's what I started with) and unfortunately > it doesn't work. > It fails if field.Elem() is nil. Try this: kind = field.Type().Elem().Kind() > > On Wednesday,

Re: [go-nuts] How to fix an awful marshal reflection hack

2022-11-30 Thread burak serdar
On Wed, Nov 30, 2022 at 5:29 AM 'Mark' via golang-nuts < golang-nuts@googlegroups.com> wrote: > I have this code which works but has a horrible hack: > ... > nullable := false > kind := field.Kind() // field's type is reflect.Value > if kind == reflect.Ptr { > This should work: kind =

Re: [go-nuts] Understanding some gotchas with linking slices together via indexing

2022-11-02 Thread burak serdar
On Tue, Nov 1, 2022 at 10:49 PM Brian, son of Bob wrote: > Can anyone explain these gotchas (demo )? > I've tried reading articles on this [one > , two >

Re: [go-nuts] Atomic pointers to arrays and sequenced-before guarantees for array elements

2022-10-30 Thread burak serdar
Based on my reading of the Go memory model, this algorithm sketch is memory-race free. However, there is a race condition. Here's the reason: The writer issues a synchronized-write to array pointer, and another synchronized-write to the array len. A reader issues a synchronized read. the

Re: [go-nuts] Detecting JSON changes

2022-10-10 Thread burak serdar
On Mon, Oct 10, 2022 at 8:50 AM 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

Re: [go-nuts] Structures / mutex question

2022-10-09 Thread burak serdar
On Sun, Oct 9, 2022 at 12:44 PM Slawomir Pryczek wrote: > Thanks, very good point about including the structure by-value. > > As for using the structure via pointer > > > You don't need to rlock the global mutex. Even if another goroutine > appends to > > the slice and slice gets reallocated,

Re: [go-nuts] Structures / mutex question

2022-10-09 Thread burak serdar
On Sun, Oct 9, 2022 at 5:49 AM Slawomir Pryczek wrote: > Hi Guys, > wanted to see if i making correct assumptions regarding mutexes and > structures > > var globalMutex sync.Mutex{} > type abc struct { > a int > b int > mu sync.Mutex{} > } > > 1. First is self explanatory, array of

Re: [go-nuts] Shared Goruntime across different microservices written in GO

2022-09-28 Thread burak serdar
On Wed, Sep 28, 2022 at 11:02 PM Roland Müller wrote: > Microservices are located in containers and making these services to use a > common binary would break the basic idea of microservices. > Not necessarily. A single binary containing multiple services gives the flexibility to be run as a

Re: [go-nuts] understanding interface conversions

2022-09-22 Thread burak serdar
s, I believe, something Go got right. > > On Sep 22, 2022, at 7:58 PM, burak serdar wrote: > >  > > > On Thu, Sep 22, 2022 at 6:30 PM Robert Engels > wrote: > >> I would like to understand the reason to type assert but not cast? That >> is an OO design

Re: [go-nuts] understanding interface conversions

2022-09-22 Thread burak serdar
ific type, or if the value underlying the interface also implements a different set of methods. And Go isn't OO. > > On Sep 22, 2022, at 7:24 PM, burak serdar wrote: > >  > > > On Thu, Sep 22, 2022 at 6:08 PM Robert Engels > wrote: > >> 100% true. The

Re: [go-nuts] understanding interface conversions

2022-09-22 Thread burak serdar
On Thu, Sep 22, 2022 at 6:08 PM Robert Engels wrote: > 100% true. The difficulty when examining a “large” system is that it > becomes very difficult to understand the relationships. Documentation can > help but it is not a great substitute for automated tools. > > In Java - actually all of OO -

Re: [go-nuts] understanding interface conversions

2022-09-22 Thread burak serdar
On Thu, Sep 22, 2022 at 4:27 PM Rory Campbell-Lange wrote: > This email follows my email yesterday "cannot convert fs.FS zip file to > io.ReadSeeker (missing Seek)". Thanks very much to those who replied and > provided solutions. > > Following that, I'm interested to learn how people negotiate

Re: [go-nuts] Re: Error-checking with errors.As() is brittle with regards to plain vs pointer types

2022-09-22 Thread burak serdar
That is not always true. I saw code that looks like this a few days ago: what the author was trying to do was to handle a specific type of error differently, and pass it along if the error is some other type: type CustomError struct{} func (e CustomError) Error() string { return "error" } func

[go-nuts] Labeled property graphs and embedded openCypher library

2022-09-20 Thread burak serdar
I would like to announce two open-source Go libraries we have been working on: Labeled Property Graphs: https://github.com/cloudprivacylabs/lpg This library supports openCypher (Neo4j) style of labeled property graphs in memory. That is: * Nodes have a set of labels, and a set of key-values,

Re: [go-nuts] Race detector question

2022-09-15 Thread burak serdar
On Thu, Sep 15, 2022 at 9:21 AM Thomas Bushnell BSG wrote: > On Thu, Sep 15, 2022 at 11:19 AM burak serdar > wrote: > >> On Thu, Sep 15, 2022 at 9:11 AM Thomas Bushnell BSG >> wrote: >> >>> I cannot speak to "other accepted concurrency designs&quo

Re: [go-nuts] Race detector question

2022-09-15 Thread burak serdar
On Thu, Sep 15, 2022 at 9:19 AM Thomas Bushnell BSG wrote: > On Thu, Sep 15, 2022 at 11:16 AM robert engels > wrote: > >> This is simply incorrect. The ‘issue’ about clarifying the memory has >> been about “happens before” since the beginning. The model was clarified. >> The race detector

Re: [go-nuts] Race detector question

2022-09-15 Thread burak serdar
;>> w.Done() >>>}() >>>w.Wait() >>> >>> } >>> >>> The above code does not have a race, or Go doesn’t have “happens before” >>> semantics with its atomics. >>> >>> >>> On Sep 15, 2022, at 9:41 AM, Rob

Re: [go-nuts] Race detector question

2022-09-15 Thread burak serdar
On Thu, Sep 15, 2022 at 8:03 AM 'Thomas Bushnell BSG' via golang-nuts < golang-nuts@googlegroups.com> wrote: > You cannot make that assumption. It's not about what the race detector can > detect. > > Goroutine one: > Writes non-synchronized X > Writes atomic Y > Writes non-synchronized Z

Re: [go-nuts] Assigning struct values

2022-09-07 Thread burak serdar
On Wed, Sep 7, 2022 at 12:28 PM Mustafa Durukan wrote: > > > *fakeObject := tt.Object.(TypeOfStruct)object := Object.(TypeOfStruct)* If you can include the definitions of tt, explain what you want to do, and what you mean by "didn't work", someone may be able to answer this question. Without

Re: [go-nuts] Struct with Interfaces fields as key in maps

2022-08-31 Thread burak serdar
On Wed, Aug 31, 2022 at 7:28 AM antonio.o...@gmail.com < antonio.ojea.gar...@gmail.com> wrote: > Hi, > > Based on the documentation: > > "The map key can be any type that is comparable." > "Struct values are comparable if all their fields are comparable. Two > struct values are equal if their

Re: [go-nuts] Pipelining with Go and Generics

2022-08-11 Thread burak serdar
On Thu, Aug 11, 2022 at 2:37 PM Robert Engels wrote: > I don’t think that is relevant. It is very difficult to do chaining with > Go’s error model. You can pass a shared context to every node and store the > error in the context and protect against concurrent access. It’s doable but > not easy.

Re: [go-nuts] Preemptive interfaces in Go

2022-08-09 Thread burak serdar
On Tue, Aug 9, 2022 at 1:52 PM Tim Peoples wrote: > Yeah, I'm with Burak on this one. The interface usage you're describing > Henry is exactly the kind of thing I'm talking about. While on the surface > it may seem advantageous -- in fact, I also tried writing Go that way when > I first started

Re: [go-nuts] Preemptive interfaces in Go

2022-08-09 Thread burak serdar
On Mon, Aug 8, 2022 at 11:27 PM Henry wrote: > I am sure that many of us have been on that journey. After using Go for > some time, we discover some practices that are not necessarily in agreement > with the existing "adages" but effectively solve our problems. > > For me, if the data type is

Re: [go-nuts] Preemptive interfaces in Go

2022-08-08 Thread burak serdar
On Mon, Aug 8, 2022 at 12:51 PM Tim Peoples wrote: > I don't necessarily consider the "multiple implementations" case as being > truly preemptive -- if there really are multiple implementations (e.g. the > "hash" package from the standard library). > > I'm much more concerned about interfaces

Re: [go-nuts] Preemptive interfaces in Go

2022-08-08 Thread burak serdar
On Mon, Aug 8, 2022 at 11:17 AM Tim Peoples wrote: > > For years I've read the old adage, "Accept interfaces, return structs" and > have spent years working to instill this understanding among my colleagues. > I gathered a great many skills while learning Go (and acquiring > readability) back

Re: [go-nuts] A pedantic question about updating a map during iteration

2022-08-02 Thread burak serdar
None of the conditions specified in that clause applies for updating key in-place. The way I read it, a new entry is not added, so the iteration should visit every entry only once. Thus, the program always prints "1 1". On Tue, Aug 2, 2022 at 9:20 PM Kevin Chowski wrote: > Hello Go gurus, > > I

Re: [go-nuts] concurrent read/write different keys in map

2022-08-02 Thread burak serdar
What exactly do you mean by "read/write 5 different keys"? If you have a map[int]*SomeStruct, for instance, and if you initialize this map with some entries, and then if you have multiple goroutines all performing lookups of distinct keys and modifying the contents of *SomeStruct, it would be

Re: [go-nuts] Re: testing examples printing to stdout not working for global var

2022-05-02 Thread burak serdar
On Mon, May 2, 2022 at 2:57 PM 'simon place' via golang-nuts < golang-nuts@googlegroups.com> wrote: > i see, thanks > > the implementation of 'go test' (which the playground runs > auto-magically.) replaces os.Stdout with a new reference behind the scenes > before running the func, but after

Re: [go-nuts] Re: testing examples printing to stdout not working for global var

2022-05-02 Thread burak serdar
On Mon, May 2, 2022 at 9:00 AM psi@gmail.com wrote: > #1 the two functions need to behave identically according to the syntax of > the language. > > #2 this is how working code operates, so testing needs to be able to > handle it. > > at a guess; 'testing' would appear to have some

Re: [go-nuts] Question regarding Golang Interfaces and composite struct

2022-04-28 Thread burak serdar
On Thu, Apr 28, 2022 at 9:49 AM Glen D souza wrote: > Consider the following piece of code > > type Dog struct { > } > > type Walker interface { > Walks() > } > > func (d *Dog) Walks() { > > } > > func CheckWalker(w Walker) { > > } > > func main() { > dog := Dog{} > CheckWalker(dog)

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

2022-04-11 Thread burak serdar
An unbuffered channel is a synchronization mechanism. A send on an unbuffered channel will block until there is a concurrent receive from another goroutine. Your program has only one goroutine. A send to an unbuffered channel will always deadlock, so will a receive from it. So the problem you are

Re: [go-nuts] RFC: function or interface?

2022-03-31 Thread burak serdar
On Thu, Mar 31, 2022 at 1:14 PM Adam Pritchard wrote: > I’m working on a library to help get the “real” client IP from HTTP > requests: > https://github.com/realclientip/realclientip-go > https://pkg.go.dev/github.com/realclientip/realclientip-go > > Right now the “strategies” are like: > > type

Re: [go-nuts] Data Structure for String Interning?

2022-01-09 Thread burak serdar
d you can allow > many more unique words by extending the interned string type to 8 > bytes. > > On Jan 9, 2022, at 3:07 PM, burak serdar wrote: > >  > Note that a with a map[string]string, the code: > > m[s]=s > > The contents of the string s are not duplicated, only the st

Re: [go-nuts] Data Structure for String Interning?

2022-01-09 Thread burak serdar
On Sun, Jan 9, 2022 at 4:30 PM jlfo...@berkeley.edu wrote: > > > On Sunday, January 9, 2022 at 3:07:18 PM UTC-8 bse...@computer.org wrote: > >> Note that a with a map[string]string, the code: >> >> m[s]=s >> >> The contents of the string s are not duplicated, only the string header s >> is. >> >

Re: [go-nuts] Data Structure for String Interning?

2022-01-09 Thread burak serdar
Note that a with a map[string]string, the code: m[s]=s The contents of the string s are not duplicated, only the string header s is. On Sun, Jan 9, 2022 at 3:52 PM jlfo...@berkeley.edu wrote: > I'm aware of Artem Krylysov's idea for string interning published on >

Re: [go-nuts] Amateur question: when you should use runes?

2021-11-15 Thread burak serdar
On Mon, Nov 15, 2021 at 11:00 AM Kamil Ziemian wrote: > Hello, > > I read quite a few blog posts, articles, listen to nice number to talks > about strings, runes and encoding in Go. I now reading Go Language Spec and > I just stuck in the section about runes. I mean, it isn't hard as itself, >

Re: [go-nuts] Why Doesn't "len()" Work With Structs?

2021-10-25 Thread 'burak serdar' via golang-nuts
On Sun, Oct 24, 2021 at 12:12 PM jlfo...@berkeley.edu < jlforr...@berkeley.edu> wrote: > I noticed that the len() function doesn't take a struct as an argument > (see below). > This is a big surprise. Can someone shed some light on why this > restriction exists? > len() gives the number of

Re: [go-nuts] Re: Why Doesn't "len()" Work With Structs?

2021-10-25 Thread 'burak serdar' via golang-nuts
On Sun, Oct 24, 2021 at 6:54 PM jlfo...@berkeley.edu wrote: > I'm now aware that that I could use > > len(([unsafe.Sizeof(T{})][0]byte{})) > > But this seems overly complicated. Plus, I don't see why > this is unsafe. Please advise. > Sizeof is unsafe because it returns the number of bytes of

Re: [go-nuts] Loading Certificate and Key from string not file for HTTPs server

2021-09-13 Thread burak serdar
On Mon, Sep 13, 2021 at 3:03 PM Sam Caldwell wrote: > Does anyone have any ideas of an easy path to load certificate and key > files from a string rather than a file? > > *Use Case:* > 1. traditionally we all put a cleartext file on disk with our private key > and public certificate. If the

Re: [go-nuts] Right way to fan out work loads

2021-09-08 Thread burak serdar
On Wed, Sep 8, 2021 at 10:02 AM David Belle-Isle wrote: > > Hi, > > I've been facing this question for a while and never managed to find the > "right" answer. Hopefully this forum will be able to enlighten me a little > bit. > > Given a very simple pattern: Consume some data, transform it, store

Re: [go-nuts] HTTP request matching different endpoint - gorilla mux

2021-09-02 Thread burak serdar
Your paths are ambiguous. "/nfdm-fdm/v2/shared-data" matches "/nfdm-fdm/v2/{id}" where id=shared_data. You can use a regex for the path with {id} to exclude the "shared_data" match. On Thu, Sep 2, 2021 at 10:13 AM Van Fury wrote: > Hi All, > > I have the following to handler functions,

[go-nuts] gofmt error formatting suggestion

2021-08-10 Thread burak serdar
Here is an idea to make reading code a bit easier: If gofmt can format this: f, err:=os.Open(file) if err!=nil { return err } as: f, err:=os.Open(file); if err!=nil { return err } it would make reading code easier by pushing the error passing code to the right. This formatting would only be

Re: [go-nuts] The behavior of the function variable which points to the struct method

2021-08-10 Thread burak serdar
On Tue, Aug 10, 2021 at 3:50 PM E Z wrote: > It works when I changed the code as your suggested. That's great, thanks. > > And I'm still a little confused here, you know when we use the struct > method directly, it is only when the function is called that the type of > receiver determines

Re: [go-nuts] The behavior of the function variable which points to the struct method

2021-08-10 Thread burak serdar
On Tue, Aug 10, 2021 at 12:01 PM E Z wrote: > I feel confused when I use the function pointer which point to the struct > method. Here is the test code: > > /*** > package main > > type Zoo struct { > Animal string > } > > func (z Zoo) Display(){ > fmt.Printf("Current animal is:%s\n",

Re: [go-nuts] Behavior to copy the value of pointer inside another pointer

2021-08-04 Thread burak serdar
On Wed, Aug 4, 2021 at 9:18 AM Olivier Szika wrote: > Hi all, > > I am surprised by the behavior of "&(*var)". > According to the language spec, pointer indirection is addressable: https://golang.org/ref/spec#Address_operators Thus, taking the address of an indirection yields the original

Re: [go-nuts] How can I check error types of gRPC calls?

2021-05-19 Thread burak serdar
Here is something I did to pass custom error information: Based on the grpc code, if an error type has GRPCStatus() *status.Status function, then grpc gets the status information using that method. For the error types that can go through grpc, I have this method below: func (e MyError)

Re: [go-nuts] Idiomatic Go code

2021-03-04 Thread burak serdar
On Thu, Mar 4, 2021 at 6:19 AM Christian von Kietzell wrote: > > Hello Gophers, > > since I obviously don't have enough Twitter followers to get more than > one answer to my Go question I'm posting it here ;-) > > Would you consider this idiomatic Go code? > >

Re: [go-nuts] Interface arguments to generic functions

2021-01-19 Thread burak serdar
On Tue, Jan 19, 2021 at 10:37 PM Ian Lance Taylor wrote: > > On Tue, Jan 19, 2021 at 8:02 PM burak serdar wrote: > > > > On Tue, Jan 19, 2021 at 8:38 PM Ian Lance Taylor wrote: > > > > > > On Tue, Jan 19, 2021 at 7:06 PM burak serdar wrote: > > > &g

Re: [go-nuts] Interface arguments to generic functions

2021-01-19 Thread burak serdar
On Tue, Jan 19, 2021 at 8:38 PM Ian Lance Taylor wrote: > > On Tue, Jan 19, 2021 at 7:06 PM burak serdar wrote: > > > > In the following program, it is valid to pass an interface to function P: > > > > func P[T fmt.Stringer](x T) { > > fmt.Println(x) >

[go-nuts] Interface arguments to generic functions

2021-01-19 Thread burak serdar
In the following program, it is valid to pass an interface to function P: func P[T fmt.Stringer](x T) { fmt.Println(x) } func main() { var v fmt.Stringer P(v) } However, there is no way for P to check if x is nil. This does not compile: func P[T fmt.Stringer](x T) { if x!=nil {

Re: [go-nuts] A new solution of type list in generic.

2020-12-28 Thread burak serdar
On Mon, Dec 28, 2020 at 7:10 PM redsto...@gmail.com wrote: > > But interface-only contracts do work here, as I suggest, only need to > introduce implicit type conversion. Type list is not so good as you say. > When defining the generic funcition max, I am not expecting number and > string,

Re: [go-nuts] json.NewDecoder()/Decode() versus Unmarshal() for single large JSON objects

2020-12-28 Thread burak serdar
On Mon, Dec 28, 2020 at 5:22 PM Amit Saha wrote: > > Hi all, let's say I am a single large JSON object that I want to > process in my HTTP server backend. > > I am trying to get my head around if there is any performance > advantage - memory or CPU to use the json.NewDecoder()/Decode() >

Re: [go-nuts] A new solution of type list in generic.

2020-12-28 Thread burak serdar
On Mon, Dec 28, 2020 at 4:30 AM redsto...@gmail.com wrote: > > If generic is inevitable, make it better. The type list in the current draft > is so special that it is added only for operators. I think it will bring > complexity and inconsistens in go. So I get an idea to replace it. There

Re: [go-nuts] Re: Generics, please go away!

2020-12-22 Thread burak serdar
On Tue, Dec 22, 2020 at 12:09 PM Anthony Martin wrote: > > 'Axel Wagner' via golang-nuts once said: > > What isn't welcome is your attempt of alienating people with a different > > viewpoint from yours and make them feel unwelcome. And if you continue to > > insist on doing that, the community

Re: [go-nuts] embedding

2020-09-28 Thread burak serdar
On Mon, Sep 28, 2020 at 10:55 AM Michał Pawełek wrote: > > https://play.golang.org/p/CBuzITRmTiP > > Why isn't T1 allowed to pass to f ? func f requires an argument of type T. You cannot pass a value of type T1. However, T1 has T embedded in it, so you can pass: f(t1.T) > > -- > You received

Re: [go-nuts] global goroutine data / thread local storage?

2020-09-23 Thread burak serdar
On Wed, Sep 23, 2020 at 6:17 PM Alex Mills wrote: > > Since by default all http requests coming to a go http server are on their > own goroutine, I am wondering if there is a way to have some sort of "global" > variable that is local to a goroutine if that makes sense, something like > this,

  1   2   3   4   5   >