Re: [go-nuts] Re: Mongo Go Models (mgm) module and order by

2023-11-22 Thread Tong Sun
Well, actually, it is at https://github.com/Kamva/mgm/issues/90, and
my previous question (#89) was asked 3 weeks ago, but nobody has
answered it yet.

This mlist is my last resort, if nobody here can answer the question,
then basically nowhere else I can find the answer. It's not the end of
the world however, as I can go back to the Mongodb Go driver directly,
although it'll be imperfect.

On Wed, Nov 22, 2023 at 12:45 PM 'Brian Candler' via golang-nuts
 wrote:
>
> https://github.com/Kamva/mgm/discussions perhaps?  (Open, but nothing posted 
> since June 2022).
>
> On Wednesday, 22 November 2023 at 17:02:35 UTC Tong Sun wrote:
>>
>> Any Mongo Go Models (mgm) user here?
>> https://github.com/Kamva/mgm
>>
>> Looks like that mgm can do aggregation but not "order by".
>> Is that so?
>>
>> Can anyone do order by with mgm please?
>>
>> PS.
>>
>> Support requests are supposed to be post to mongo-go-models Google Group, 
>> however, that seems to be gone and searching Mongo Go Models (mgm) in Google 
>> Group landed me here into this mlist instead.
>>
> --
> You received this message because you are subscribed to a topic in the Google 
> Groups "golang-nuts" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/golang-nuts/PznHZtNrB6Q/unsubscribe.
> To unsubscribe from this group and all its topics, 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/e309dafc-6971-4651-a6d1-5f9483bdc747n%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMmz1Oc37PT5OU%2Bt6szSzxtXoOMYdaL7csc6dbwo7dAJcbMJJQ%40mail.gmail.com.


[go-nuts] Mongo Go Models (mgm) module and order by

2023-11-22 Thread Tong Sun
Any Mongo Go Models (mgm) user here?
https://github.com/Kamva/mgm

Looks like that mgm can do aggregation but not "order by".
Is that so? 

Can anyone do order by with mgm please?

PS. 

Support requests are supposed to be post to mongo-go-models Google Group 
, however, that 
seems to be gone and searching Mongo Go Models (mgm) in Google Group landed 
me here into this mlist instead. 

-- 
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/9c6faf3a-7504-4eb3-9f91-4e03aa0281ban%40googlegroups.com.


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

2023-11-16 Thread Tong Sun
Thanks for the hint. would you elaborate a bit more please as I'm still 
unsure how to do it. and the closes hits that I found are


   - 
   
https://stackoverflow.com/questions/71739971/unmarshalling-a-bson-d-object-golang
   - https://www.mongodb.com/docs/drivers/go/current/fundamentals/bson/
   

But neither covers how to unmarshal bson.M types. I got either:

cannot use r (variable of type interface{}) as []byte value in argument to 
bson.Unmarshal: need type assertion

Or with:

r := val["author"].(primitive.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["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 
> 
https://stackoverflow.com/questions/60072372/filtering-values-out-of-a-bson-m-in-golang/
 
> where the answer says to use `range server.installed` while the comment 
says 
> 
> server.host undefined (type string has no field or method subject) 
> 
> This is what I've tried with the MongoDB `[]bson.M{}` type results 
(obtained from like `$lookup`): 
> 
> The []bson.M{} type of result I'm getting is: 
> 
> [map[_id:ObjectID("65529d178688bac31b739f82") 
author:[map[_id:ObjectID("65529d168688bac31b739f81") 
created_at:1699912982379 name:Mehran updated_at:1699912982379]] 
author_id:ObjectID("65529d168688bac31b739f81") created_at:1699912983386 
name:Test pages:124 updated_at:1699912983386]] 
> 
> I've made several attempts but was unable to access the author field of 
the lookup result in Go. 
> 
> a := []author{} 
> for _, val := range result { a = append(a, 
val["author"].(primitive.A)[0]) } 
> 
> If using val.author, I'm getting val.author undefined (type primitive.M 
has no field or method author) 
> If using val["author"], I'm getting invalid operation: cannot index 
val["author"] (map index expression of type interface{}) 
> If using val["author"].(primitive.A)[0], I'm getting cannot use 
val["author"].(primitive.A)[0] (variable of type interface{}) as author 
value in argument to append: need type assertion 
> 
> 
> And how to go about to fix this "need type assertion" just stumbled me, 
as I've tried val["author"].(primitive.A).([]main.author)[0], or 
[]author(val["author"].(primitive.A))[0], but I'm getting invalid 
operation: cannot call non-function val["author"].(primitive.A) (comma, ok 
expression of type primitive.A) 
> 
> and I've now run out of ideas how to fix it. 
> Please help 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d3d75521-c618-45f1-a734-59730cf01364n%40googlegroups.com.


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

2023-11-16 Thread Tong Sun
Further on with the question 
https://stackoverflow.com/questions/60072372/filtering-values-out-of-a-bson-m-in-golang/
where the answer says to use `range server.installed` while the comment says

server.host undefined (type string has no field or method subject)

This is what I've tried with the MongoDB `[]bson.M{}` type results 
(obtained from like `$lookup`):

The []bson.M{} type of result I'm getting is:

[map[_id:ObjectID("65529d178688bac31b739f82") 
author:[map[_id:ObjectID("65529d168688bac31b739f81") 
created_at:1699912982379 name:Mehran updated_at:1699912982379]] 
author_id:ObjectID("65529d168688bac31b739f81") created_at:1699912983386 
name:Test pages:124 updated_at:1699912983386]] 

I've made several attempts but was unable to access the author field of the 
lookup result in Go.
a := []author{} 
for _, val := range result { a = append(a, val["author"].(primitive.A)[0]) }


   - If using val.author, I'm getting val.author undefined (type 
   primitive.M has no field or method author)
   - If using val["author"], I'm getting invalid operation: cannot index 
   val["author"] (map index expression of type interface{})
   - If using val["author"].(primitive.A)[0], I'm getting cannot use 
   val["author"].(primitive.A)[0] (variable of type interface{}) as author 
   value in argument to append: *need type assertion*


And how to go about to fix this "need type assertion" just stumbled me, as 
I've tried val["author"].(primitive.A).([]main.author)[0], or 
[]author(val["author"].(primitive.A))[0], but I'm getting invalid 
operation: cannot call non-function val["author"].(primitive.A) (comma, ok 
expression of type primitive.A)

and I've now run out of ideas how to fix it. 
Please help


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4c9bfd40-4de6-4423-9c0e-31b79b144bd5n%40googlegroups.com.


Re: [go-nuts] go run, add string value definition with space

2023-11-13 Thread Tong Sun
Yep, works like a charm. thx!

On Mon, Nov 13, 2023 at 4:34 AM Michel Levieux 
wrote:

> Hi!
>
> Not an expert at all, but it seems the format is
> "package-qualified.identifier=value", with value being able to just contain
> spaces out of the box, so running:
>
> go run -ldflags="-X 'main.MyVar=this is a string'" main.go
>
> works for me. Note that for parsing the whole thing correctly, the whole
> equality should be surrounded by quotes (i.e. including the main.MyVar part)
>
> Hope that helps!
>
> On Thu, Nov 9, 2023 at 10:26 PM Tong Sun  wrote:
>
>> go run command-line-arguments
>>
>>   -X definition
>> add string value definition of the form importpath.name=value
>>
>> I used to use this to override my variable values, in the form of
>>
>> go run -ldflags="-X main.var1=val1 main.var2=val2"
>>
>> Now, the new problem is that I need to have space in the string value
>> definition. How can I do that please?
>>
>> I've tried both the following cases:
>>
>> go run -ldflags="-X main.var1='val 1' main.var2=\"val 2\""
>>
>> but neither is working.
>> Please help
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/golang-nuts/7d1e2b06-dce9-4e46-b20b-fe5a3663038en%40googlegroups.com
>> <https://groups.google.com/d/msgid/golang-nuts/7d1e2b06-dce9-4e46-b20b-fe5a3663038en%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>
>
> *Évènement en ligne : inscription ici
> <https://info.doctolib.fr/events/bienvenue-dans-le-nouveau-doctolib/?utm_campaign=nurt_FR_Generic_email_signature_20231030_source=automation_medium=email>*
> *The information transmitted, including attachments, is intended only for *
> *the **person(s) or **entity to which it is addressed and may contain 
> **confidential
> and/or privileged material. Any **review, retransmission, **dissemination
> or other use of, or taking of any action in reliance **upon **this
> information by persons or entities other than the intended recipient **is
> prohibited. If **you received this in error, please contact the sender
> and **destroy any copies of this **information.*
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMmz1Ofy1fkOqK_wWaTSXDQKeoADO7uEMiV6HB2Qvr91qLM%3DFQ%40mail.gmail.com.


[go-nuts] go run, add string value definition with space

2023-11-09 Thread Tong Sun
go run command-line-arguments

  -X definition
add string value definition of the form importpath.name=value

I used to use this to override my variable values, in the form of

go run -ldflags="-X main.var1=val1 main.var2=val2"

Now, the new problem is that I need to have space in the string value 
definition. How can I do that please?

I've tried both the following cases:

go run -ldflags="-X main.var1='val 1' main.var2=\"val 2\""

but neither is working. 
Please help


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7d1e2b06-dce9-4e46-b20b-fe5a3663038en%40googlegroups.com.


Re: [go-nuts] Dynamic template data from yaml

2023-10-14 Thread Tong Sun


On Saturday, October 14, 2023 at 3:47:54 PM UTC-4 Dan Kortschak wrote:

On Sat, 2023-10-14 at 09:33 -0700, Tong Sun wrote: 
> Please take a look at  
> https://go.dev/play/p/dTDR50dtHB0 
> 
> I want to 
> 
> - define my template data dynamically from yaml 
> - and export the yaml data if they are unexported 
> 
> I.e., for the following code: 
> 
> t := template.New("") 
> t, err = t.Parse("It's {{.A}} {{.B.C}}!\n") 
> if err != nil { 
> log.Fatalf("error: %v", err) 
> } 
> t.Execute(os.Stdout, m) 
> 
> The input is `map[A:Easy! B:map[C:2 D:[3 4]]]`. 
> But why the template was not able to produce any output for the 
> dynamic fields? 

It is trying to match a string to a main.MyKey. If the only reason you 
are using that type is to change the case of the key strings, I'd just 
index into the lowercase, https://go.dev/play/p/wi9KICK1zmW.


 wow, thanks.

Hmm... somehow I had the impression that only the exported fields can be 
used in template as variables.

Is that a wrong impression or things have changed?


-- 
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/8a2df85b-5d5a-4a9d-b0ae-8cc3d46b7aa3n%40googlegroups.com.


[go-nuts] Dynamic template data from yaml

2023-10-14 Thread Tong Sun
Please take a look at 
https://go.dev/play/p/dTDR50dtHB0

I want to

- define my template data dynamically from yaml
- and export the yaml data if they are unexported

I.e., for the following code:

t := template.New("")
t, err = t.Parse("It's {{.A}} {{.B.C}}!\n")
if err != nil {
log.Fatalf("error: %v", err)
}
t.Execute(os.Stdout, m)

The input is `map[A:Easy! B:map[C:2 D:[3 4]]]`.
But why the template was not able to produce any output for the dynamic 
fields?

The error is `<.A>: can't evaluate field A in type map[main.MyKey]interface 
{}`
Why is that and how to fix it please?

Thanks

PS. Whole program included below:

-
package main

import (
"fmt"
"log"
"os"
"strings"
"text/template"

"gopkg.in/yaml.v3"
)

var data = `
a: Easy!
b:
  c: 2
  d: [3, 4]
`

type MyKey string

func (k *MyKey) UnmarshalYAML(n *yaml.Node) error {
var s string
if err := n.Decode(); err != nil {
return err
}
*k = MyKey(strings.ToUpper(s))
return nil
}

func main() {
m := make(map[MyKey]any)

err := yaml.Unmarshal([]byte(data), )
if err != nil {
log.Fatalf("error: %v", err)
}
fmt.Printf("--- m:\n%v\n\n", m)

d, err := yaml.Marshal()
if err != nil {
log.Fatalf("error: %v", err)
}
fmt.Printf("--- m dump:\n%s\n\n", string(d))

t := template.New("")
t, err = t.Parse("It's {{.A}} {{.B.C}}!\n")
if err != nil {
log.Fatalf("error: %v", err)
}
err = t.Execute(os.Stdout, m)
if err != nil {
log.Fatalf("error: %v", err)
}
}
-

-- 
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/3f7484d6-fbcd-4b88-aeeb-f581e9eb4952n%40googlegroups.com.


[go-nuts] Using go module 101, undefined types

2023-09-11 Thread Tong Sun
This is really a go module 101 question, as I'm trying to understand and 
solve the *undefined types* problem that I'm having.

I have:

$ head -1 go.mod
module backend


And in my internal/petstore/main.go file, I have:

package main

import api "backend/internal/petstore/interfaces/ports"

func main() {
petStore := api.NewPetStore()
}


And in my internal/petstore/interfaces/ports/type.go file, I have:

package api
type PetStore struct {...}


I think it should compile, but I'm getting:

$ go run internal/petstore/main.go
# command-line-arguments
internal/petstore/main.go:..:38: undefined: api.PetStore


and I have no idea how to fix it.

I also tried to build the whole project with `go build .`, but got

no Go files in 

Please help. thx.

-- 
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/ee028af4-3de2-468c-9ef2-48d8a2ac24cbn%40googlegroups.com.


Fwd: [go-nuts] simplistic web based chat solution

2023-07-23 Thread Tong Sun
Sending to the group instead.

On Sun, Jul 23, 2023 at 12:46 AM Eli Lindsey  wrote:
>
> I’m taking a stab at answering, but I didn’t quite follow your intent and may 
> have misunderstood your question. Please let me know if that’s the case. :)
>
> I'm having a hard time putting it into my code. Specifically, how to handle 
> incoming new chats message and push to all web base clients. What's the 
> simplest solution for it?
>
>
> It’ll probably be easiest if you define what the client is/what protocol the 
> client speaks and work back from there. Skimming the code, it looks like your 
> demo is speaking http to web browsers and the chat example you’re interested 
> in merging is a custom protocol (a very simple one, “echo what’s received”) 
> on bare tcp. You have many options: if your clients are something like 
> netcat, you can define the protocol to initially be http with an html 
> response that then switches to tcp echo; if your clients are web browsers, 
> some strategies to consider (from least to most complicated) are periodic 
> polling, long polling, and a protocol that supports push out of the box like 
> WebTransport.
>
> If you want the simplest version that works in a web browser, I would write 
> it so that the user has to manually refresh (or click a button) to see new 
> messages. Once that works you could then look into how to make the client 
> pull new messages without a manual refresh, but that’s likely to be 
> client-side js and not server-side go, so may or may not be interesting 
> depending on what you’re wanting to learn from this exercise.

Ah, yeah, manual refreshing is simplest to do. Good idea!

> Note, to avoid user hitting refresh and lost all past conversation, I was 
> planning to store all of them, including the connect variable returned from 
> `net.Dial` into cookies. I know that there is a 4K size limit to total 
> cookies size, but that's OK with me for such a simplest chatting service, 
> which would add as minimum to the solution from ch8/chat as possible.
>
>
> I’m not entirely sure what you’re describing here, but carrying the net.Conn 
> in a cookie sounds odd. Could you say more?

Starting from
https://github.com/adonovan/gopl.io/blob/master/ch8/netcat3/netcat.go

Indeed, it is a custom protocol (a very simple one, “echo what’s
received”) on bare tcp. How it works on cli is that each client starts
their own cli client, having their own net.Conn for the whole
communication, and will get new messages from there.

Now, when shifting that onto a web service, where only one instance
would serve all different clients, the only thing *I can think of* is
to

- spinning up a new chatting client goroutine (mainly the quoted code
in OP) when a new user logs in, then there will be a new net.Conn for
the client
- since I'm only doing server side programming and one server needs to
serve different clients, the only way I can think of is to store their
own net.Conn in their own cookies to track individual status
- to avoid users hitting refresh and losing all past conversations, I
think I have to store the conversation (since login) in cookies as
well.

Hmm... on second thought, since I'm planning to let users do their
manual refreshing, maybe store the whole conversation on the server
and when refresh, it prints from the 1st line again might be another
option.

What would you think is the easiest thing to do here? Thanks!


> On Jul 22, 2023, at 11:26 PM, Tong Sun  wrote:
>
> I know web based chatting service can be as complicated as possible, but I 
> want to build a web based chat server that is as simple as possible.
>
> And the chapter 8 of the book "The Go Programming Language" at
> https://github.com/adonovan/gopl.io/tree/master/ch8/chat
> seems to be a perfect starting point to learn the asynchronous web based chat 
> service building.
>
> I've built a whole (simplest) web service that support user login and logout, 
> at:
> https://github.com/suntong/lang/blob/master/lang/Go/src/net/HttpD/demo-redirect.go
> and was planning that the next logic steps would be to
>
> - incorporate the chat server as another goroutine besides my web server, and
> - add the chatting to my web service by spinning up a new chatting client 
> goroutine when a new user logs in.
>
> However, it is incorporating the chatting client into my web service that 
> made my head spinning none-stop. IE, for the following few lines of code from
> https://github.com/adonovan/gopl.io/blob/master/ch8/netcat3/netcat.go
>
> done := make(chan struct{})
> go func() {
> io.Copy(os.Stdout, conn) // NOTE: ignoring errors
> log.Println("done")
> done <- struct{}{} // signal the main goroutine
> }()
> mustCopy(conn, os.Stdin)
> conn.Close()
> <-done // wait for background goroutine to f

[go-nuts] simplistic web based chat solution

2023-07-22 Thread Tong Sun
I know web based chatting service can be as complicated as possible, but I 
want to build a web based chat server that is as simple as possible. 

And the chapter 8 of the book "The Go Programming Language" at
https://github.com/adonovan/gopl.io/tree/master/ch8/chat
seems to be a perfect starting point to learn the asynchronous web 
based chat service building.

I've built a whole (simplest) web service that support user login and 
logout, at:
https://github.com/suntong/lang/blob/master/lang/Go/src/net/HttpD/demo-redirect.go
and was planning that the next logic steps would be to

- incorporate the chat server as another goroutine besides my web server, 
and
- add the chatting to my web service by spinning up a new chatting client 
goroutine when a new user logs in.

However, it is incorporating the chatting client into my web service that 
made my head spinning none-stop. IE, for the following few lines of code 
from
https://github.com/adonovan/gopl.io/blob/master/ch8/netcat3/netcat.go

done := make(chan struct{})
go func() {
io.Copy(os.Stdout, conn) // NOTE: ignoring errors
log.Println("done")
done <- struct{}{} // signal the main goroutine
}()
mustCopy(conn, os.Stdin)
conn.Close()
<-done // wait for background goroutine to finish

I'm having a hard time putting it into my code. Specifically, how to handle 
incoming new chats message and push to all web base clients. What's the 
simplest solution for it? 
Note, to avoid user hitting refresh and lost all past conversation, I was 
planning to store all of them, including the connect variable returned from 
`net.Dial` into cookies. I know that there is a 4K size limit to total 
cookies size, but that's OK with me for such a simplest chatting service, 
which would add as minimum to the solution from ch8/chat as possible.

Anybody can help please?


-- 
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/e3327bc2-4f2f-4038-b38d-0c9794ec6235n%40googlegroups.com.


[go-nuts] net/http: invalid byte in Cookie.Value; dropping invalid bytes

2023-07-21 Thread Tong Sun
Hi Gophers, 

I'm facing a very weird error:

func getUserName(w http.ResponseWriter, r *http.Request) string {
c, err := r.Cookie("session")
if err != nil {
http.Redirect(w, r, rootUrl, http.StatusSeeOther)
return ""
}
log.Println("session raw", c.Value)

var s session
fmt.Printf("%+v\n", s)
reader := strings.NewReader(c.Value)
if err := gob.NewDecoder(reader).Decode(); err != nil {
log.Println(err)
http.Error(w, "server error: gob decoding", http.StatusInternalServerError)
return ""
}

return s.Name // userName
}

With the above code, I'm getting the following:

2023/07/21 18:11:00 net/http: invalid byte '\x7f' in Cookie.Value; dropping 
invalid bytes
2023/07/21 18:11:00 session raw 
{Name: Text:}
2023/07/21 18:11:00 unexpected EOF

The Cookie session is encoded with gob Encode. It should only contain plain 
text strings right? So where does the problem come from?

The whole program is at:
https://github.com/suntong/lang/blob/master/lang/Go/src/net/HttpD/demo-redirect.go

The recent change that got me into the problem is:
https://github.com/suntong/lang/commit/ee5adac80edaf3b8d04e483b2257786268d5250f

Please help. Thx.


-- 
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/13e154d0-d456-4e56-84f3-b28ad734d633n%40googlegroups.com.


[go-nuts] Re: gopl ch8 ex8.14, Go Chat server that allows client names

2023-07-07 Thread Tong Sun
Oh, please disregard my question -- I've figured it out.

On Friday, July 7, 2023 at 6:28:32 PM UTC-4 Tong Sun wrote:

> For the chapter 8 of the book "The Go Programming Language":
>
> https://github.com/adonovan/gopl.io/tree/master/ch8/chat
>
> The exercise 8.14 is about using names instead of network addresses to 
> identify clients, and I'm having problem with how to implement it.
>
> I searched for "answers/solutions" on the web, and found that *all* of 
> them will prompt for keyboard input in the `handleConn` function, like this 
> one:
> https://github.com/mohno007/gopl/blob/master/ch08/ex14/chat.go
>
> However, my understanding is that
>
> - the chat will be running as a (single) service in one machine, and
> - all clients (from the localnet) will be chatting with `netcat3`
>
> IE, I don't see how different clients from different machines will be 
> prompted for keyboard input if they start chatting with `netcat3`. Is my 
> such understanding correct please? (and what's the proper way of doing it 
> if so)
>
> thanks
>
>
>
>
>
>

-- 
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/c5b04f35-c481-46c4-974f-d916121d27dbn%40googlegroups.com.


[go-nuts] gopl ch8 ex8.14, Go Chat server that allows client names

2023-07-07 Thread Tong Sun
For the chapter 8 of the book "The Go Programming Language":

https://github.com/adonovan/gopl.io/tree/master/ch8/chat

The exercise 8.14 is about using names instead of network addresses to 
identify clients, and I'm having problem with how to implement it.

I searched for "answers/solutions" on the web, and found that *all* of them 
will prompt for keyboard input in the `handleConn` function, like this one:
https://github.com/mohno007/gopl/blob/master/ch08/ex14/chat.go

However, my understanding is that

- the chat will be running as a (single) service in one machine, and
- all clients (from the localnet) will be chatting with `netcat3`

IE, I don't see how different clients from different machines will be 
prompted for keyboard input if they start chatting with `netcat3`. Is my 
such understanding correct please? (and what's the proper way of doing it 
if so)

thanks





-- 
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/9b2e9693-4091-42c2-a43b-dcc73a13f2c2n%40googlegroups.com.


Re: [go-nuts] Error wrapping not always work??

2022-05-01 Thread Tong Sun
Got it. Thanks a lot sir.

On Sunday, May 1, 2022 at 2:53:29 PM UTC-4 axel.wa...@googlemail.com wrote:

> To be clear: You seem to assume that `errors.Is` recursively unwraps both 
> errors passed to it and checks for equality along any of their pairings (or 
> maybe in the innermost wrapped error). But that's not the case.
> errors.Is checks if the first error wraps the second.
> One error wrapping another is not an equivalence relationship. eGot 
> wrapping ErrInvalidArgument does not mean ErrInvalidArgument wraps eGot. 
> eExpected also wrapping ErrInvalidArgument also does not mean that eGot 
> wraps eExpected (or vice versa). One error wrapping another is an 
> asymmetric relationship between the two - can you get to the second by 
> recursively unwrapping the first.
>
> On Sun, May 1, 2022 at 8:46 PM Axel Wagner  
> wrote:
>
>>
>>
>> On Sun, May 1, 2022 at 6:12 PM Tong Sun  wrote:
>>
>>>
>>>
>>> On Sunday, May 1, 2022 at 11:17:35 AM UTC-4 axel.wa...@googlemail.com 
>>> wrote:
>>>
>>>> In the first case, you ask if the respective errors wrap e1. The answer 
>>>> is yes - both wrap e1.
>>>> In the second case, you ask if one error wraps the other. The answer is 
>>>> no - they both wrap ErrInvalidArgument, but they don't wrap each other.
>>>>
>>>
>>> Are you talking about the following two checks?
>>>
>>> if errors.Is(e2, e1)
>>>
>>
>> This checks if e2 wraps e1. Which it does, as it was created via
>> return fmt.Errorf("I'm adding further more context: %w", e1)
>>  
>>
>>> if errors.Is(eGot, eExpected)
>>>
>>
>> This checks if eGot wraps eExpected. Which it doesn't. They are 
>> constructed as
>> eExpected := fmt.Errorf("grpc: InvalidArgument, cannot deposit %v: %w", 
>> -1.11, ErrInvalidArgument)
>> eGot := fmt.Errorf("cannot deposit %v: %w", -1.11, ErrInvalidArgument)
>> Clearly, eGot does not wrap eExpected. Both of them wrap 
>> ErrInvalidArgument. But that is not the same as wrapping each other.
>>
>> If you want to check that they are both wrapping ErrInvalidArgument, use
>> errors.Is(eGot, ErrInvalidArgument)
>> errors.Is(eExpected, ErrInvalidArgument)
>>
>> If you want to make eGot wrap eExpected, use
>> eGot := fmt.Errorf("cannot deposit %v: %w", -1.11, eExpected)
>>
>>
>>> I see both are checking if the respective errors are wrapping (from) the 
>>> same error.
>>>  
>>> Why one works and one doesn't?
>>>
>>> errors.Is doesn't check if both errors passed wrap the same error - they 
>>>> check if the first argument wraps the other.
>>>>
>>>> On Sun, May 1, 2022 at 4:56 PM Tong Sun  wrote:
>>>>
>>>>> Please take a look at
>>>>> https://go.dev/play/p/Dl_IGD46bPe
>>>>>
>>>>> I have two error wrappings there, one works and one doesn't (I'm 
>>>>> expecting both to be the "Same"). Why one works and one doesn't?
>>>>>
>>>>> thanks
>>>>>
>>>>> -- 
>>>>> 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...@googlegroups.com.
>>>>> To view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/golang-nuts/3a1c9ad1-8d7c-481a-bfbb-4d4c94cc8f72n%40googlegroups.com
>>>>>  
>>>>> <https://groups.google.com/d/msgid/golang-nuts/3a1c9ad1-8d7c-481a-bfbb-4d4c94cc8f72n%40googlegroups.com?utm_medium=email_source=footer>
>>>>> .
>>>>>
>>>> -- 
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/47ceb9a6-8b4f-441b-b694-438ac8764c01n%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/golang-nuts/47ceb9a6-8b4f-441b-b694-438ac8764c01n%40googlegroups.com?utm_medium=email_source=footer>
>>> .
>>>
>>

-- 
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/90542e33-62d3-43af-beb6-d10c4bed9f54n%40googlegroups.com.


Re: [go-nuts] Error wrapping not always work??

2022-05-01 Thread Tong Sun


On Sunday, May 1, 2022 at 11:17:35 AM UTC-4 axel.wa...@googlemail.com wrote:

> In the first case, you ask if the respective errors wrap e1. The answer is 
> yes - both wrap e1.
> In the second case, you ask if one error wraps the other. The answer is no 
> - they both wrap ErrInvalidArgument, but they don't wrap each other.
>

Are you talking about the following two checks?

if errors.Is(e2, e1)
if errors.Is(eGot, eExpected)

I see both are checking if the respective errors are wrapping (from) the 
same error.
 
Why one works and one doesn't?

errors.Is doesn't check if both errors passed wrap the same error - they 
> check if the first argument wraps the other.
>
> On Sun, May 1, 2022 at 4:56 PM Tong Sun  wrote:
>
>> Please take a look at
>> https://go.dev/play/p/Dl_IGD46bPe
>>
>> I have two error wrappings there, one works and one doesn't (I'm 
>> expecting both to be the "Same"). Why one works and one doesn't?
>>
>> thanks
>>
>> -- 
>> 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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/3a1c9ad1-8d7c-481a-bfbb-4d4c94cc8f72n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/3a1c9ad1-8d7c-481a-bfbb-4d4c94cc8f72n%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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/47ceb9a6-8b4f-441b-b694-438ac8764c01n%40googlegroups.com.


[go-nuts] Error wrapping not always work??

2022-05-01 Thread Tong Sun
Please take a look at
https://go.dev/play/p/Dl_IGD46bPe

I have two error wrappings there, one works and one doesn't (I'm expecting 
both to be the "Same"). Why one works and one doesn't?

thanks

-- 
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/3a1c9ad1-8d7c-481a-bfbb-4d4c94cc8f72n%40googlegroups.com.


[go-nuts] Re: [generics] generic method parameters

2022-04-30 Thread Tong Sun
Thanks a lot sir!

On Saturday, April 30, 2022 at 4:56:44 PM UTC-4 vzdra...@gmail.com wrote:

> Here is a working version of the Get & Set methods without changing your 
> method signatures. https://go.dev/play/p/MAqFwVINvd8 
>
> On Saturday, April 30, 2022 at 2:43:31 PM UTC-6 sunto...@gmail.com wrote:
>
>> I've done many reading on Go generic method parameters, and it seems 
>> *somewhat* supported, like from
>>
>> https://markphelps.me/posts/trying-out-generics-in-go/
>>
>> A generic Get() & Set() can be defined and used:
>>
>> 
>> // Set sets the value.
>> func (o *Optional[T]) Set(v T) {
>>o.value = 
>> }
>>
>> ... 
>>
>> Now the user of my library could write code like this:
>>
>> o := New(42)
>> v, err := o.Get()
>> 
>>
>> However, I was having a hard time trying to apply that to my following 
>> code:
>> https://go.dev/play/p/p8FMYHEFRUK
>>
>> Is it possible to get its generic Get() & Set() function working (which 
>> is currently commented out)?
>>
>> Thanks
>>
>>

-- 
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/07680055-957e-408d-934e-fdabdcd5842fn%40googlegroups.com.


[go-nuts] [generics] generic method parameters

2022-04-30 Thread Tong Sun
I've done many reading on Go generic method parameters, and it seems 
*somewhat* supported, like from

https://markphelps.me/posts/trying-out-generics-in-go/

A generic Get() & Set() can be defined and used:


// Set sets the value.
func (o *Optional[T]) Set(v T) {
   o.value = 
}

... 

Now the user of my library could write code like this:

o := New(42)
v, err := o.Get()


However, I was having a hard time trying to apply that to my following code:
https://go.dev/play/p/p8FMYHEFRUK

Is it possible to get its generic Get() & Set() function working (which is 
currently commented out)?

Thanks

-- 
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/34ca780c-86fe-4006-afb0-c2859804f8dbn%40googlegroups.com.


Re: [go-nuts] Missing /usr/lib/go/pkg/include/ for native binaries

2022-04-08 Thread Tong Sun
On Fri, Apr 8, 2022 at 2:00 AM Jack Li  wrote:
>
> Yes, I download the latest go 1.18 installer for macOS from golang.google.cn. 
> There's no problem with the installer from the official site.
>
>
> -- Original --
> From: "Ian Lance Taylor";
> Date: 2022年4月8日(星期五) 上午7:40
> To: "Tong Sun";
> Cc: "golang-nuts";
> Subject: Re: [go-nuts] Missing /usr/lib/go/pkg/include/ for native binaries
>
> On Thu, Apr 7, 2022 at 2:35 PM Tong Sun  wrote:
> >
> > This might be the first go package that I do `go get` and which requires 
> > native binaries:
> >
> > $ go get -v go.opentelemetry.io/otel/exporters/stdout/stdouttrace
> > golang.org/x/sys/unix
> > # golang.org/x/sys/unix
> > /.../Go/pkg/mod/golang.org/x/sys@v0.0.0-20210423185535-09eb48e85fd7/unix/asm_linux_amd64.s:9:
> >  #include: open /usr/lib/go-1.17/pkg/include/textflag.h: no such file or 
> > directory
> >
> > I checked and found that I'm missing the whole 
> > /usr/lib/go-1.17/pkg/include/ directory.
> >
> > How can I get them so that my `go get` can be successful?
> >
> > Thanks
> >
> > $ go version
> > go version go1.17.6 linux/amd64
> >
> > $ lsb_release -a
> > No LSB modules are available.
> > Distributor ID: Debian
> > Description:Debian GNU/Linux bullseye/sid
> > Release:   10.12
> > Codename:  buster
> >
> > $ apt-cache policy golang-1.17-src
> > golang-1.17-src:
> >   Installed: 1.17.6-1~bpo11+1
> >   Candidate: 1.17.8-1~bpo11+1
> >   Version table:
> >  1.17.8-1~bpo11+1 100
> > 100 http://deb.debian.org/debian bullseye-backports/main amd64 
> > Packages
> >  *** 1.17.6-1~bpo11+1 100
> > 100 /var/lib/dpkg/status
>
> That's odd.  File a bug report against Debian?  I don't know why they
> are missing.
>
> You can of course get the header files you need by installing Go
> yourself (https://go.dev/doc/install).
>
> Ian

Thank you both,

I reported the problem to Debian, as I didn't find the include/
directory in either,
https://packages.debian.org/sid/all/golang-1.17-src/filelist
https://packages.debian.org/sid/all/golang-1.18-src/filelist

but it turns out to be *my own* problem. I.e.,

either the Debian package or the official one are OK.

Thanks 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/CAMmz1OfCNr4SbQ-HWkgadTd5GD7%2BS4a6W-8N4Qqux%2BfOxMhZ5Q%40mail.gmail.com.


[go-nuts] Missing /usr/lib/go/pkg/include/ for native binaries

2022-04-07 Thread Tong Sun
This might be the first go package that I do `go get` and which requires 
native binaries:

$ go get -v go.opentelemetry.io/otel/exporters/stdout/stdouttrace
golang.org/x/sys/unix
# golang.org/x/sys/unix
/.../Go/pkg/mod/golang.org/x/sys@v0.0.0-20210423185535-09eb48e85fd7/unix/asm_linux_amd64.s:9:
 
#include: open /usr/lib/go-1.17/pkg/include/textflag.h: no such file or 
directory

I checked and found that I'm missing the 
whole /usr/lib/go-1.17/pkg/include/ directory.

How can I get them so that my `go get` can be successful?

Thanks

$ go version
go version go1.17.6 linux/amd64

$ lsb_release -a 
No LSB modules are available.
Distributor ID: Debian
Description:Debian GNU/Linux bullseye/sid
Release:   10.12
Codename:  buster

$ apt-cache policy golang-1.17-src
golang-1.17-src:
  Installed: 1.17.6-1~bpo11+1
  Candidate: 1.17.8-1~bpo11+1
  Version table:
 1.17.8-1~bpo11+1 100
100 http://deb.debian.org/debian bullseye-backports/main amd64 
Packages
 *** 1.17.6-1~bpo11+1 100
100 /var/lib/dpkg/status

-- 
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/fb6dfce0-98ef-4b9f-ab3b-d14055f39c53n%40googlegroups.com.


Re: [go-nuts] all goroutines are asleep - deadlock!

2022-03-25 Thread Tong Sun
Oh, thanks for the explain and pointing out `go vet` for future problems. 

Thanks!

On Friday, March 25, 2022 at 12:08:39 PM UTC-4 jake...@gmail.com wrote:

> The WaitGroup Documentation  says " A 
> WaitGroup must not be copied after first use.". 
>
> You are passing around and calling choppingActivity by value, so it is 
> being copied after Add() is called, and again each call to choppingAction() 
> and choppingSimulation(). 
>
> If you run "go vet" on your code it will alert you to the problems. 
>
> On Friday, March 25, 2022 at 10:27:02 AM UTC-4 sunto...@gmail.com wrote:
>
>> *Re-using the old thread for a new problem that I'm getting:*
>>
>> fatal error: all goroutines are asleep - deadlock!
>>
>> I rewrote my 
>> https://github.com/suntong/lang/blob/master/lang/Go/src/sys/butchers.go 
>> files from procedure based to OO based, as
>> https://github.com/suntong/lang/tree/master/lang/Go/src/sys/butchersOO
>>
>> The two programs behaves exactly the same, however my new "OO" approach 
>> ended with 
>>
>> fatal error: all goroutines are asleep - deadlock!
>> goroutine 1 [semacquire]:
>>
>> The only reason that I can think of is that,
>>
>> I changed my goroutine calling from function calling of
>> `go choppingProblem(i, knifeLeft, knifeRight)`
>> (
>> https://github.com/suntong/lang/blob/9057e5718e00d396d0fe9a232820bdb79a31df72/lang/Go/src/sys/butchers.go#L79-L82
>> )
>>
>> to method calling of
>> `go chopping.choppingAction(i, knifeLeft, knifeRight, )`
>> (
>> https://github.com/suntong/lang/blob/9057e5718e00d396d0fe9a232820bdb79a31df72/lang/Go/src/sys/butchersOO/main.go#L129-L132
>> )
>>
>> Might that be the reason? 
>> How to fix the problem?
>>
>> Thanks
>>
>>
>>

-- 
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/b3e5deba-8325-481e-9f5d-a115406da728n%40googlegroups.com.


Re: [go-nuts] all goroutines are asleep - deadlock!

2022-03-25 Thread Tong Sun
*Re-using the old thread for a new problem that I'm getting:*

fatal error: all goroutines are asleep - deadlock!

I rewrote my 
https://github.com/suntong/lang/blob/master/lang/Go/src/sys/butchers.go 
files from procedure based to OO based, as
https://github.com/suntong/lang/tree/master/lang/Go/src/sys/butchersOO

The two programs behaves exactly the same, however my new "OO" approach 
ended with 

fatal error: all goroutines are asleep - deadlock!
goroutine 1 [semacquire]:

The only reason that I can think of is that,

I changed my goroutine calling from function calling of
`go choppingProblem(i, knifeLeft, knifeRight)`
(https://github.com/suntong/lang/blob/9057e5718e00d396d0fe9a232820bdb79a31df72/lang/Go/src/sys/butchers.go#L79-L82)

to method calling of
`go chopping.choppingAction(i, knifeLeft, knifeRight, )`
(https://github.com/suntong/lang/blob/9057e5718e00d396d0fe9a232820bdb79a31df72/lang/Go/src/sys/butchersOO/main.go#L129-L132)

Might that be the reason? 
How to fix the problem?

Thanks


-- 
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/beee5c10-9c8d-4c25-b418-ebe77349938fn%40googlegroups.com.


Re: [go-nuts] Re: Getting started with gocc

2022-01-09 Thread Tong Sun
On Sun, Jan 9, 2022 at 4:56 PM Ian Lance Taylor  wrote:
>
> On Sun, Jan 9, 2022, 1:26 PM Tong Sun  wrote:
>>
>> Hi,
>>
>> I'm following with
>> https://github.com/goccmack/gocc/blob/master/doc/gocc_user_guide.pdf
>>
>> and I'm at the step of trying to provide my own ast:
>>
>> For a single bnf of:
>>
>> Hello:  "hello" id << ast.NewHello($1) >> ;
>>
>> (https://github.com/suntong/lang/blob/master/lang/Go/src/parsers/gocc/ex3-hello/hello.bnf)
>>
>> How to provide the corresponding ast.go?
>>
>> My first try was:
>>
>> https://github.com/suntong/lang/blob/master/lang/Go/src/parsers/gocc/ex3-hello/ast/ast.go
>>
>> and I've made several other attempts, but still unable to make it work.
>
>
> These kinds of questions might be better directed to the people who maintain 
> gocc.  I don't know whether they read this mailing list, which is about the 
> Go language in general.

OK, I'll keep that in mind next time. BTW, I've fixed it --

https://github.com/suntong/lang/tree/master/lang/Go/src/parsers/gocc/ex3-hello

-- 
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/CAMmz1OcD8zLWaAW1ozfx2rf5NLoAZHHJSA4ehY6BJ7P6HBhoHA%40mail.gmail.com.


[go-nuts] Re: Getting started with gocc

2022-01-09 Thread Tong Sun
Hi,

I'm following with
https://github.com/goccmack/gocc/blob/master/doc/gocc_user_guide.pdf

and I'm at the step of trying to provide my own ast:

For a single bnf of:

Hello:  "hello" id << ast.NewHello($1) >> ;

(https://github.com/suntong/lang/blob/master/lang/Go/src/parsers/gocc/ex3-hello/hello.bnf)

How to provide the corresponding ast.go?

My first try was:

https://github.com/suntong/lang/blob/master/lang/Go/src/parsers/gocc/ex3-hello/ast/ast.go

and I've made several other attempts, but still unable to make it work.

please help.

On Sun, Jan 9, 2022 at 12:37 PM Tong Sun wrote:

> How to overcome such hurdle? thx!

Set

GO111MODULE=on

fixed 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/CAMmz1OcNjs%2BEaSr9tgQnoYu%3DgEA9yTwj_exgPNiXcyweNPJdKA%40mail.gmail.com.


[go-nuts] Getting started with gocc

2022-01-09 Thread Tong Sun
Hi,

I'm following with
https://github.com/goccmack/gocc/blob/master/doc/gocc_user_guide.pdf

and I'm at the step of trying to install gocc:

```
$ go get -v github.com/goccmack/gocc
github.com/goccmack/gocc (download)
get "golang.org/x/mod/modfile": found meta tag
vcs.metaImport{Prefix:"golang.org/x/mod", VCS:"git",
RepoRoot:"https://go.googlesource.com/mod"} at
//golang.org/x/mod/modfile?go-get=1
get "golang.org/x/mod/modfile": verifying non-authoritative meta tag
golang.org/x/mod (download)
cannot find package "golang.org/x/mod/modfile" in any of:
/usr/lib/go-1.17/src/golang.org/x/mod/modfile (from $GOROOT)
/.../Go/src/golang.org/x/mod/modfile (from $GOPATH)

$ go get -v golang.org/x/mod/modfile
get "golang.org/x/mod/modfile": found meta tag
vcs.metaImport{Prefix:"golang.org/x/mod", VCS:"git",
RepoRoot:"https://go.googlesource.com/mod"} at
//golang.org/x/mod/modfile?go-get=1
get "golang.org/x/mod/modfile": verifying non-authoritative meta tag
golang.org/x/mod (download)
cannot find package "golang.org/x/mod/modfile" in any of:
/usr/lib/go-1.17/src/golang.org/x/mod/modfile (from $GOROOT)
/.../Go/src/golang.org/x/mod/modfile (from $GOPATH)

$ go get -v golang.org/x/mod/
package golang.org/x/mod: no Go files in /.../Go/src/golang.org/x/mod
```

How to overcome such hurdle? thx!

-- 
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/CAMmz1Oe%2B32RfW4qi%3DspRpFcixH3u2ZxUZe%3D3nwTmTLYfRHQh3A%40mail.gmail.com.


[go-nuts] Re: Problem using embed in Go 1.16

2021-10-10 Thread Tong Sun


On Sunday, October 10, 2021 at 12:23:27 PM UTC-4 Tong Sun wrote:

> Ahh, found it but you beat me to it.
>
> Apparently the sample code that I'm referring to,
> https://github.com/treeverse/blogs/blob/master/mypostcard/main.go
> from https://lakefs.io/working-with-embed-in-go/
> is outdated. 
>

Ops, I was wrong, again. 
 

> Thanks!
>
> On Sunday, October 10, 2021 at 12:20:42 PM UTC-4 seank...@gmail.com wrote:
>
>> import _ "embed"
>>
>> It means to import it for side effects only
>>
>> On Sunday, October 10, 2021 at 6:12:07 PM UTC+2 sunto...@gmail.com wrote:
>>
>>> Hi,
>>>
>>> I'm having problem using embed with Go 1.16. I'm getting ether
>>>
>>> - //go:embed only allowed in Go files that import "embed"
>>> - or imported and not used: "embed"
>>>
>>> The test code is published at
>>> https://github.com/suntong/lang/tree/master/lang/Go/src/ds/embed
>>>
>>> here are the details:
>>>
>>> If I remove the "embed" Go import, I'll get:
>>>
>>> $ go build
>>> # github.com/suntong/lang/lang/Go/src/ds/embed
>>> ./embeding.go:17:3: //go:embed only allowed in Go files that import 
>>> "embed"
>>>
>>> If I add back the "embed" Go import, I'll get:
>>>
>>> $ go build
>>> # github.com/suntong/lang/lang/Go/src/ds/embed
>>> ./embeding.go:11:2: imported and not used: "embed"
>>>
>>> $ go version
>>> go version go1.16.6 linux/amd64
>>>
>>> $ lsb_release -a 
>>> No LSB modules are available.
>>> Distributor ID: Debian
>>> Description:Debian GNU/Linux bullseye/sid
>>> Release:10.10
>>> Codename:   buster
>>>
>>> The main file:
>>>
>>> ---
>>> package main
>>>
>>> import (
>>> "embed"
>>> "flag"
>>> "fmt"
>>> "os"
>>> )
>>>
>>> //go:embed cpuArch.txt
>>> var cpuArch string
>>>
>>> func usage() {
>>> // Fprintf allows us to print to a specifed file handle or stream
>>> fmt.Fprintf(os.Stderr, "\nUsage: %s [flags] file [path ...]\n\n",
>>> "CommandLineFlag") // os.Args[0]
>>> flag.PrintDefaults()
>>> os.Exit(0)
>>> }
>>>
>>> func main() {
>>> fmt.Printf("Before parsing the flags\n")
>>> fmt.Printf("CPU: '%s'\n", cpuArch)
>>>
>>> flag.StringVar(, "cpu", "AMD64", "CPU Arch")
>>>
>>> flag.Usage = usage
>>> flag.Parse()
>>>
>>> // There is also a mandatory non-flag arguments
>>> if len(flag.Args()) < 1 {
>>> usage()
>>> }
>>>
>>> fmt.Printf("\nAfter parsing the flags\n")
>>> fmt.Printf("CPU: '%s'\n", cpuArch)
>>>
>>> }
>>> ---
>>>
>>>
>>>

-- 
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/1edf57d5-f7c5-47ec-b49c-f07085a607d5n%40googlegroups.com.


[go-nuts] Re: Problem using embed in Go 1.16

2021-10-10 Thread Tong Sun
Ahh, found it but you beat me to it.

Apparently the sample code that I'm referring to,
https://github.com/treeverse/blogs/blob/master/mypostcard/main.go
from https://lakefs.io/working-with-embed-in-go/
is outdated. 

Thanks!

On Sunday, October 10, 2021 at 12:20:42 PM UTC-4 seank...@gmail.com wrote:

> import _ "embed"
>
> It means to import it for side effects only
>
> On Sunday, October 10, 2021 at 6:12:07 PM UTC+2 sunto...@gmail.com wrote:
>
>> Hi,
>>
>> I'm having problem using embed with Go 1.16. I'm getting ether
>>
>> - //go:embed only allowed in Go files that import "embed"
>> - or imported and not used: "embed"
>>
>> The test code is published at
>> https://github.com/suntong/lang/tree/master/lang/Go/src/ds/embed
>>
>> here are the details:
>>
>> If I remove the "embed" Go import, I'll get:
>>
>> $ go build
>> # github.com/suntong/lang/lang/Go/src/ds/embed
>> ./embeding.go:17:3: //go:embed only allowed in Go files that import 
>> "embed"
>>
>> If I add back the "embed" Go import, I'll get:
>>
>> $ go build
>> # github.com/suntong/lang/lang/Go/src/ds/embed
>> ./embeding.go:11:2: imported and not used: "embed"
>>
>> $ go version
>> go version go1.16.6 linux/amd64
>>
>> $ lsb_release -a 
>> No LSB modules are available.
>> Distributor ID: Debian
>> Description:Debian GNU/Linux bullseye/sid
>> Release:10.10
>> Codename:   buster
>>
>> The main file:
>>
>> ---
>> package main
>>
>> import (
>> "embed"
>> "flag"
>> "fmt"
>> "os"
>> )
>>
>> //go:embed cpuArch.txt
>> var cpuArch string
>>
>> func usage() {
>> // Fprintf allows us to print to a specifed file handle or stream
>> fmt.Fprintf(os.Stderr, "\nUsage: %s [flags] file [path ...]\n\n",
>> "CommandLineFlag") // os.Args[0]
>> flag.PrintDefaults()
>> os.Exit(0)
>> }
>>
>> func main() {
>> fmt.Printf("Before parsing the flags\n")
>> fmt.Printf("CPU: '%s'\n", cpuArch)
>>
>> flag.StringVar(, "cpu", "AMD64", "CPU Arch")
>>
>> flag.Usage = usage
>> flag.Parse()
>>
>> // There is also a mandatory non-flag arguments
>> if len(flag.Args()) < 1 {
>> usage()
>> }
>>
>> fmt.Printf("\nAfter parsing the flags\n")
>> fmt.Printf("CPU: '%s'\n", cpuArch)
>>
>> }
>> ---
>>
>>
>>

-- 
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/4f792810-ecad-4544-8732-c3ae4f4b30c8n%40googlegroups.com.


[go-nuts] Problem using embed in Go 1.16

2021-10-10 Thread Tong Sun
Hi,

I'm having problem using embed with Go 1.16. I'm getting ether

- //go:embed only allowed in Go files that import "embed"
- or imported and not used: "embed"

The test code is published at
https://github.com/suntong/lang/tree/master/lang/Go/src/ds/embed

here are the details:

If I remove the "embed" Go import, I'll get:

$ go build
# github.com/suntong/lang/lang/Go/src/ds/embed
./embeding.go:17:3: //go:embed only allowed in Go files that import "embed"

If I add back the "embed" Go import, I'll get:

$ go build
# github.com/suntong/lang/lang/Go/src/ds/embed
./embeding.go:11:2: imported and not used: "embed"

$ go version
go version go1.16.6 linux/amd64

$ lsb_release -a 
No LSB modules are available.
Distributor ID: Debian
Description:Debian GNU/Linux bullseye/sid
Release:10.10
Codename:   buster

The main file:

---
package main

import (
"embed"
"flag"
"fmt"
"os"
)

//go:embed cpuArch.txt
var cpuArch string

func usage() {
// Fprintf allows us to print to a specifed file handle or stream
fmt.Fprintf(os.Stderr, "\nUsage: %s [flags] file [path ...]\n\n",
"CommandLineFlag") // os.Args[0]
flag.PrintDefaults()
os.Exit(0)
}

func main() {
fmt.Printf("Before parsing the flags\n")
fmt.Printf("CPU: '%s'\n", cpuArch)

flag.StringVar(, "cpu", "AMD64", "CPU Arch")

flag.Usage = usage
flag.Parse()

// There is also a mandatory non-flag arguments
if len(flag.Args()) < 1 {
usage()
}

fmt.Printf("\nAfter parsing the flags\n")
fmt.Printf("CPU: '%s'\n", cpuArch)

}
---


-- 
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/4124bd7e-f5b1-4259-a433-05959021d05cn%40googlegroups.com.


[go-nuts] Understanding benchstat's output

2021-07-27 Thread Tong Sun
Hi, 

I'm trying to understand the benchstat's output. 
The benchstat that I have is fresh from golang.org/x/perf/cmd/, installed 
hours ago.

This is understandable:

nameold time/opnew time/opdelta
FormatEmoji-2 1.79µs ± 0%1.82µs ± 1%   ~ (p=0.100 n=3+3)
FormatEmoji-4 1.99µs ± 1%1.91µs ± 4%   ~ (p=0.200 n=3+3)
FormatEmoji-8 1.97µs ± 3%1.99µs ± 1%   ~ (p=0.700 n=3+3)
FormatEmoji-122.05µs ± 1%2.03µs ± 1%   ~ (p=0.400 n=3+3)

nameold alloc/op   new alloc/op   delta
FormatEmoji-2   384B ± 0%  384B ± 0%   ~ (p=1.000 n=3+3)
FormatEmoji-4   386B ± 0%  385B ± 0%   ~ (p=0.700 n=3+3)
FormatEmoji-8   387B ± 0%  386B ± 0%   ~ (p=0.400 n=3+3)
FormatEmoji-12  388B ± 0%  388B ± 0%   ~ (p=1.000 n=3+3)

nameold allocs/op  new allocs/op  delta
FormatEmoji-2   7.00 ± 0%  7.00 ± 0%   ~ (all equal)
FormatEmoji-4   7.00 ± 0%  7.00 ± 0%   ~ (all equal)
FormatEmoji-8   7.00 ± 0%  7.00 ± 0%   ~ (all equal)
FormatEmoji-12  7.00 ± 0%  7.00 ± 0%   ~ (all equal)

However, 

Why benchstat thinks there is no differences between the following two runs?

$ benchstat /tmp/old.log /tmp/new.log
name  old time/opnew time/opdelta
FormatEmojiString-2 1.79µs ± 0%6.81µs ± 2%   ~ (p=0.100 n=3+3)
FormatEmojiString-4 1.99µs ± 1%7.22µs ± 1%   ~ (p=0.100 n=3+3)
FormatEmojiString-8 1.97µs ± 3%7.55µs ± 2%   ~ (p=0.100 n=3+3)
FormatEmojiString-122.05µs ± 1%7.64µs ± 1%   ~ (p=0.100 n=3+3)

name  old alloc/op   new alloc/op   delta
FormatEmojiString-2   384B ± 0% 1459B ± 0%   ~ (p=0.100 n=3+3)
FormatEmojiString-4   386B ± 0% 1463B ± 0%   ~ (p=0.100 n=3+3)
FormatEmojiString-8   387B ± 0% 1468B ± 0%   ~ (p=0.100 n=3+3)
FormatEmojiString-12  388B ± 0% 1473B ± 0%   ~ (p=0.100 n=3+3)

name  old allocs/op  new allocs/op  delta
FormatEmojiString-2   7.00 ± 0% 25.00 ± 0%   ~ (p=0.100 n=3+3)
FormatEmojiString-4   7.00 ± 0% 25.00 ± 0%   ~ (p=0.100 n=3+3)
FormatEmojiString-8   7.00 ± 0% 25.00 ± 0%   ~ (p=0.100 n=3+3)
FormatEmojiString-12  7.00 ± 0% 25.00 ± 0%   ~ (p=0.100 n=3+3)

I'd think that the delta will be quite big. 

Now take a look at this. benchstat thinks there is no differences between 
the following two runs is beyond imagination:

$ benchstat /tmp/old.log /tmp/new.log
name old time/opnew time/op  delta
FormatEmojiBlock-2 1.79µs ± 0%  13543.09µs ± 4%   ~ (p=0.100 n=3+3)
FormatEmojiBlock-4 1.99µs ± 1%  14597.09µs ± 1%   ~ (p=0.100 n=3+3)
FormatEmojiBlock-8 1.97µs ± 3%  16390.62µs ± 2%   ~ (p=0.100 n=3+3)
FormatEmojiBlock-122.05µs ± 1%  17409.37µs ± 2%   ~ (p=0.100 n=3+3)

name old alloc/op   new alloc/op delta
FormatEmojiBlock-2   384B ± 0%   15270330B ± 0%   ~ (p=0.100 n=3+3)
FormatEmojiBlock-4   386B ± 0%   15270671B ± 0%   ~ (p=0.100 n=3+3)
FormatEmojiBlock-8   387B ± 0%   15271206B ± 0%   ~ (p=0.100 n=3+3)
FormatEmojiBlock-12  388B ± 0%   15271727B ± 0%   ~ (p=0.100 n=3+3)

name old allocs/op  new allocs/opdelta
FormatEmojiBlock-2   7.00 ± 0% 3467.00 ± 0%   ~ (p=0.100 n=3+3)
FormatEmojiBlock-4   7.00 ± 0% 3467.00 ± 0%   ~ (p=0.100 n=3+3)
FormatEmojiBlock-8   7.00 ± 0% 3467.00 ± 0%   ~ (p=0.100 n=3+3)
FormatEmojiBlock-12  7.00 ± 0% 3467.00 ± 0%   ~ (p=0.100 n=3+3)

What's happening? What I've done wrong?

Thx

-- 
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/a56a17b1-a8c3-4926-a27a-21cd86074f67n%40googlegroups.com.


Re: [go-nuts] Re: Help me troubleshoot this missing value problem

2021-06-19 Thread Tong Sun
Ah, thanks a lot Sean!

On Sat, Jun 19, 2021 at 6:52 PM Sean Liao  wrote:

> You're accessing .SecondKS when it should be .Shortcut.SecondKS (as you
> correctly do for .Shortcut.FirstKS)
>
> https://play.golang.org/p/Jzxws3JaTSQ
>
> side note: I think it's easier to read if you also use indenting in your
> templates and use `{{- -}}` to trim leading/trailing whitespace
>
> On Sunday, June 20, 2021 at 12:05:11 AM UTC+2 sunto...@gmail.com wrote:
>
>> Please take a look at
>>
>> https://play.golang.org/p/k_CM_cJgSvJ
>>
>> line 77 tries to output .FirstKS then .SecondKS if it is not nil
>>
>> However, there are two cases, the debug output shows there is .SecondKS
>> field but the template thinks there is ``:
>>
>> alt MINUS map[Id:EditorCutLineBackward
>> Shortcut:map[FirstKS:alt MINUS SecondKS:control K]] EditorCutLineBackward
>> control C map[Id:RunToCursor Shortcut:map[FirstKS:control C
>> SecondKS:control U]] RunToCursor
>>
>> I've run out of ideas how it could possibly happen.
>>
>> Somebody help please. thx
>>
>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/3NUjoj_Bakc/unsubscribe.
> To unsubscribe from this group and all its topics, 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/4c37e558-296f-4274-b7fd-679f4d50954en%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMmz1OdZfHbHcziN-GjOCbv0uXcoxAADPpEQaOT%3DCUpVpVbDHw%40mail.gmail.com.


[go-nuts] Re: Convert json to css for golang

2021-06-19 Thread Tong Sun
Can you express your converting from json to css using Golang template rule?


On Saturday, June 19, 2021 at 3:51:32 AM UTC-4 muhorto...@gmail.com wrote:

> Hi everyone, I need a converter from json to css.I use 
> https://github.com/ysugimoto, it translates css to json, then I connect 
> some plugins that change the json, and after that I need to recreate it 
> back to css. Do not advise Postcss because I'm just trying to make it 
> similar to Golang
>

-- 
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/b2238961-0316-47f3-be12-bcbcc1d66657n%40googlegroups.com.


[go-nuts] Help me troubleshoot this missing value problem

2021-06-19 Thread Tong Sun
Please take a look at

https://play.golang.org/p/k_CM_cJgSvJ

line 77 tries to output .FirstKS then .SecondKS if it is not nil

However, there are two cases, the debug output shows there is .SecondKS 
field but the template thinks there is ``:

alt MINUS map[Id:EditorCutLineBackward Shortcut:map[FirstKS:alt 
MINUS SecondKS:control K]] EditorCutLineBackward
control C map[Id:RunToCursor Shortcut:map[FirstKS:control C 
SecondKS:control U]] RunToCursor 
 
I've run out of ideas how it could possibly happen. 

Somebody help please. thx


-- 
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/c964e9f9-5c68-4c72-bb82-6e97a7b3a443n%40googlegroups.com.


[go-nuts] Go code review site?

2021-04-04 Thread Tong Sun
I remember I've been to a page/site where people can ask for review for 
their open source projects, commits, etc. 

Is there such site/service, or my memory has fainted (e.g., it's for go 
core only etc)?

thanks

-- 
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/1a3c8525-9bfd-43d6-9b63-17ffac3dc2cdn%40googlegroups.com.


Re: [go-nuts] pkg.go.dev Documentation section empty

2021-03-18 Thread Tong Sun
( Sorry Alex, didn't meant to sent to you personally )

Oh, thanks. Just realized that the Documentation section is only for
modules, right?

I.e., mine is an executable, and this is the first time I'm looking at
my docs on pkg.go.dev, in which my long readme is "missing", the whole
page is almost empty, with the gopher-flying-airplane picture taking
the majority of the empty space, until just now I realized that I
should click on that "Expand" button. Sorry...

On Thu, Mar 18, 2021 at 7:30 PM Axel Wagner
 wrote:
>
> Hi,
>
> https://go.dev/about#adding-a-package gives general information about adding 
> a module.
> One of the most common reasons why documentation might not show up is that 
> your module doesn't contain an open source license that pkg.go.dev 
> recognizes. https://pkg.go.dev/license-policy contains some information on 
> that.
> If you provide us with a link to your module, we might be able to give you 
> more specific information about what is wrong.
>
> On Fri, Mar 19, 2021 at 12:11 AM Tong Sun  wrote:
>>
>> The "Documentation" section is empty for my package on pkg.go.dev.
>>
>> Where can I read how to fix it?
>>
>> Thanks
>>
>>
>> --
>> 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/88896681-cac3-4dac-bf4b-568b5cd8c5c4n%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMmz1Ofxvhwy5fpSLmtSJ3dR3ncqy89sqTp6ueeQja9kLQ8a3w%40mail.gmail.com.


[go-nuts] pkg.go.dev Documentation section empty

2021-03-18 Thread Tong Sun
The "Documentation" section is empty for my package on pkg.go.dev. 

Where can I read how to fix it?

Thanks


-- 
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/88896681-cac3-4dac-bf4b-568b5cd8c5c4n%40googlegroups.com.


Re: [go-nuts] Re: Go based xml manipulation library

2021-02-14 Thread Tong Sun
Thank you Santhosh!

Can the https://github.com/santhosh-tekuri/xpath model edit or delete
elements, apart from locating them?
If so, are there any ready-made examples/blogs etc that I can refer to?

Thx!

On Sun, Feb 14, 2021 at 4:28 PM Santhosh Kumar T
 wrote:
>
> You can try https://github.com/santhosh-tekuri/xpath. it uses 
> https://github.com/santhosh-tekuri/xpath as model.
>
> BTW, I am author of the above projects
>
> - santhosh
>
> On Friday, February 12, 2021 at 10:30:57 PM UTC+5:30 sunto...@gmail.com wrote:
>>
>> Thanks Steve,
>>
>> That's what I thought, but on taking a closer look, especially the getting 
>> to the `following-sibling` part, I didn't find any API that I can make use 
>> of out of the box. Hence --
>>
>> https://github.com/beevik/etree/issues/99
>>
>> Could you elaborate on how to get to the `following-sibling` part of a given 
>> element for etree please? Using 
>> http://zvon.org/comp/r/tut-XPath_1.html#Pages~Following-sibling_axis as the 
>> example, in either place will do. thx
>>
>>
>> On Thursday, February 11, 2021 at 7:17:40 PM UTC-5 st...@rothskeller.net 
>> wrote:
>>>
>>> github.com/beevik/etree does much of what you're looking for.
>>> Steve
>>>
>>> On Thursday, February 11, 2021 at 1:10:51 PM UTC-8 sunto...@gmail.com wrote:

 Is there any Go library that allow certain following-sibling manipulation?

 Specifically, I want to,

 locate an xml node via XPath
 delete its following-sibling

 More or less like this, 
 http://zvon.org/comp/r/tut-XPath_1.html#Pages~Following-sibling_axis, but 
 to delete the node, instead of just locating it.

 thx



> --
> You received this message because you are subscribed to a topic in the Google 
> Groups "golang-nuts" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/golang-nuts/X_Di8cLEncU/unsubscribe.
> To unsubscribe from this group and all its topics, 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/e3ad6d21-07aa-41c7-93d1-f68d50018645n%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMmz1OciDvUrkeSzVCbXpC37e1ecMkpMOfhxfinReQxcaD7_dw%40mail.gmail.com.


[go-nuts] Re: Go based xml manipulation library

2021-02-12 Thread Tong Sun
Thanks Steve, 

That's what I thought, but on taking a closer look, especially the getting 
to the `following-sibling` part, I didn't find any API that I can make use 
of out of the box. Hence --

https://github.com/beevik/etree/issues/99

Could you elaborate on how to get to the `following-sibling` part of a 
given element for etree please? Using 
http://zvon.org/comp/r/tut-XPath_1.html#Pages~Following-sibling_axis as the 
example, in either place will do. thx


On Thursday, February 11, 2021 at 7:17:40 PM UTC-5 st...@rothskeller.net 
wrote:

> github.com/beevik/etree does much of what you're looking for.
> Steve
>
> On Thursday, February 11, 2021 at 1:10:51 PM UTC-8 sunto...@gmail.com 
> wrote:
>
>> Is there any Go library that allow certain following-sibling 
>>  manipulation?
>>
>> Specifically, I want to,
>>
>>- locate an xml node via XPath
>>- delete its following-sibling
>>
>> More or less like this, 
>> http://zvon.org/comp/r/tut-XPath_1.html#Pages~Following-sibling_axis, 
>> but to delete the node, instead of just locating it.
>>
>> thx
>>
>>
>>
>>

-- 
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/b1048c9f-3502-463c-8555-1d59ae9dfd36n%40googlegroups.com.


[go-nuts] Go based xml manipulation library

2021-02-11 Thread Tong Sun


Is there any Go library that allow certain following-sibling 
 manipulation?

Specifically, I want to,

   - locate an xml node via XPath
   - delete its following-sibling

More or less like this, 
http://zvon.org/comp/r/tut-XPath_1.html#Pages~Following-sibling_axis, but 
to delete the node, instead of just locating it.

thx



-- 
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/446d2e41-4351-4fd3-bce5-6b2406efdfcdn%40googlegroups.com.


Re: [go-nuts] Need to read file in double loop

2021-01-12 Thread Tong Sun
Ops. sorry, it is. Wonder why it wasn't working before (tried at least twice).

On Tue, Jan 12, 2021 at 3:12 PM Tong Sun  wrote:
>
> That's a typo. Changing it to "E" you'd think the problem is solved?
>
> On Mon, Jan 11, 2021 at 10:14 PM Kurtis Rader  wrote:
> >
> > You should start by asking yourself why your program outputs "1", "2" and 
> > "S". Hint: after seeing "S" you don't break out of the inner loop until 
> > another "S" is seen which your sample data does not include.
> >
> > On Mon, Jan 11, 2021 at 6:59 PM Tong Sun  wrote:
> >>
> >> Hi,
> >>
> >> I need to read file in double loop --
> >>
> >> - reading file line by line until a special KW is met, say "S"
> >> - When it happens, need to collect content line by line until another 
> >> special KW is met, say "E"
> >>
> >> For e.g., if processing the following content line by line, then the 
> >> content from S 3 till 6 E need to be processed as a *single group*:
> >>
> >> 1
> >> 2
> >> S
> >> 3
> >> 4
> >> 5
> >> 6
> >> E
> >> 7
> >> 8
> >> 9
> >>
> >> How can I do that?
> >>
> >> I've prepared a starter
> >> https://play.golang.org/p/brdLtyjt-L2
> >>
> >> but it is not working as I expected
> >>
> >> Why 7 8 9 are not processed?
> >> How to fix it?
> >>
> >> Thx!
> >>
> >>
> >> --
> >> 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/db7e8fee-11f7-4e7a-8743-c6e3096342e4n%40googlegroups.com.
> >
> >
> >
> > --
> > Kurtis Rader
> > Caretaker of the exceptional canines Junior and Hank

-- 
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/CAMmz1OcOEc9YFV-B6SDqVfJ951%3Do2Jbb5zXUejWvL8q4ZYqOiw%40mail.gmail.com.


Re: [go-nuts] Need to read file in double loop

2021-01-12 Thread Tong Sun
That's a typo. Changing it to "E" you'd think the problem is solved?

On Mon, Jan 11, 2021 at 10:14 PM Kurtis Rader  wrote:
>
> You should start by asking yourself why your program outputs "1", "2" and 
> "S". Hint: after seeing "S" you don't break out of the inner loop until 
> another "S" is seen which your sample data does not include.
>
> On Mon, Jan 11, 2021 at 6:59 PM Tong Sun  wrote:
>>
>> Hi,
>>
>> I need to read file in double loop --
>>
>> - reading file line by line until a special KW is met, say "S"
>> - When it happens, need to collect content line by line until another 
>> special KW is met, say "E"
>>
>> For e.g., if processing the following content line by line, then the content 
>> from S 3 till 6 E need to be processed as a *single group*:
>>
>> 1
>> 2
>> S
>> 3
>> 4
>> 5
>> 6
>> E
>> 7
>> 8
>> 9
>>
>> How can I do that?
>>
>> I've prepared a starter
>> https://play.golang.org/p/brdLtyjt-L2
>>
>> but it is not working as I expected
>>
>> Why 7 8 9 are not processed?
>> How to fix it?
>>
>> Thx!
>>
>>
>> --
>> 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/db7e8fee-11f7-4e7a-8743-c6e3096342e4n%40googlegroups.com.
>
>
>
> --
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank

-- 
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/CAMmz1OcPqgRv1kiByABSn6QZuSg_%3D6Ee4Yg186R8V396yyno4g%40mail.gmail.com.


[go-nuts] Need to read file in double loop

2021-01-11 Thread Tong Sun
Hi, 

I need to read file in double loop -- 

- reading file line by line until a special KW is met, say "S"
- When it happens, need to collect content line by line until another 
special KW is met, say "E"

For e.g., if processing the following content line by line, then 
the content from S 3 till 6 E need to be processed as a *single group*:

1
2
S
3
4
5
6
E
7
8
9

How can I do that?

I've prepared a starter
https://play.golang.org/p/brdLtyjt-L2

but it is not working as I expected

Why 7 8 9 are not processed?
How to fix it?

Thx!


-- 
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/db7e8fee-11f7-4e7a-8743-c6e3096342e4n%40googlegroups.com.


Re: [go-nuts] Re: The latest version of package in pkg.go.dev

2020-08-15 Thread Tong Sun
Oh, thanks.

The very reason that I do that is to avoid the following situation:

for i in `jot 12`; do echo $i > f; git commit -am "$i"; git tag v0.0.$i; done

$ git tag -l
v0.0.1
v0.0.10
v0.0.11
v0.0.12
v0.0.2
v0.0.3
v0.0.4
v0.0.5
v0.0.6
v0.0.7
v0.0.8
v0.0.9

If no leading 0s allowed, how do you guys solve the above problem?


On Sat, Aug 15, 2020 at 5:01 AM seank...@gmail.com  wrote:
>
> that's an invalid semver, no leading 0s  allowed
>
> https://semver.org/#spec-item-2 :
> A normal version number MUST take the form X.Y.Z where X, Y, and Z are 
> non-negative integers, and MUST NOT contain leading zeroes. X is the major 
> version, Y is the minor version, and Z is the patch version. Each element 
> MUST increase numerically. For instance: 1.9.0 -> 1.10.0 -> 1.11.0.
>
> On Saturday, August 15, 2020 at 4:08:06 AM UTC+2 sunto...@gmail.com wrote:
>>
>> How to force update the latest version of package in pkg.go.dev?
>>
>> My https://github.com/go-easygen/easygen/releases/tag/v5.1.01 has been 
>> release for over 10 days, but the 
>> https://pkg.go.dev/github.com/go-easygen/easygen?tab=versions is still 
>> showing an old version.
>>
>> From https://proxy.golang.org/ I saw
>>
>>> explicitly request that version via go get module@version. After one minute 
>>> for caches to expire, the go command will see that tagged version. If this 
>>> doesn't work for you, please file an issue.
>>
>>
>>
>> So I did:
>>
>>
>> go get github.com/go-easygen/eas...@v5.1.01
>>
>> go: downloading github.com/go-easygen/easygen 
>> v4.0.1-0.20200804033944-7bacacfacf6a+incompatible
>> go: github.com/go-easygen/easygen v5.1.01 => 
>> v4.0.1-0.20200804033944-7bacacfacf6a+incompatible
>> go: finding module for package gopkg.in/yaml.v2
>> . . .
>>
>> $ date
>> Fri Aug 14 21:56:06 EDT 2020
>>
>> $ lynx -dump -width=78 
>> "https://pkg.go.dev/github.com/go-easygen/easygen?tab=versions;; date
>> . . .
>> v1 - github.com/go-easygen/easygen
>>
>>  * [32]v4.1.0+incompatible - Jun 19, 2019
>>  * [33]v4.0.0+incompatible - Mar 24, 2019
>>  * [34]v3.0.0+incompatible - May 4, 2018
>> . . .
>> Fri Aug 14 22:06:18 EDT 2020
>>
>>
>> So do I need to file an issue, or I've missed something?
>>
>> Thx
>>
>>
> --
> You received this message because you are subscribed to a topic in the Google 
> Groups "golang-nuts" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/golang-nuts/ECa7ZlbLNW0/unsubscribe.
> To unsubscribe from this group and all its topics, 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/074b1e7d-7b1c-43c0-abc6-d20eb2625c7dn%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMmz1OdXGXc5D86oMdC2ABZ%2BuSER_P8hb7piimNPac3enihjeA%40mail.gmail.com.


[go-nuts] The latest version of package in pkg.go.dev

2020-08-14 Thread Tong Sun
How to force update the latest version of package in pkg.go.dev?

My https://github.com/go-easygen/easygen/releases/tag/v5.1.01 has been 
release for over 10 days, but the 
https://pkg.go.dev/github.com/go-easygen/easygen?tab=versions is still 
showing an old version. 

>From https://proxy.golang.org/ I saw

explicitly request that version via go get module@version. After one minute 
> for caches to expire, the go command will see that tagged version. If this 
> doesn't work for you, please file an issue 
> .



So I did:


go get github.com/go-easygen/easygen@v5.1.01

go: downloading github.com/go-easygen/easygen 
v4.0.1-0.20200804033944-7bacacfacf6a+incompatible
go: github.com/go-easygen/easygen v5.1.01 => 
v4.0.1-0.20200804033944-7bacacfacf6a+incompatible
go: finding module for package gopkg.in/yaml.v2
. . . 

$ date
Fri Aug 14 21:56:06 EDT 2020

$ lynx -dump 
-width=78 "https://pkg.go.dev/github.com/go-easygen/easygen?tab=versions;; 
date
. . . 
v1 - github.com/go-easygen/easygen

 * [32]v4.1.0+incompatible - Jun 19, 2019
 * [33]v4.0.0+incompatible - Mar 24, 2019
 * [34]v3.0.0+incompatible - May 4, 2018
. . . 
Fri Aug 14 22:06:18 EDT 2020


So do I need to file an issue 
, or I've missed 
something? 

Thx


-- 
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/0854db20-1596-4709-930d-23ddde7063f9o%40googlegroups.com.


[go-nuts] Go Present, Decoration on the first and last page

2020-07-27 Thread Tong Sun
Hi, 

Any way to apply some decorations on the first and last page of the sides 
of Go Present?

I used `.background` for each of my sides, which looks really nice, but now 
the first and last page of the sides looks really out of the league. 

Any comment welcome. 

thanks

-- 
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/903e5a43-4d2e-4722-952a-33a4c90ef329o%40googlegroups.com.


[go-nuts] Re: go module @latest found but does not contain package

2020-07-25 Thread Tong Sun
Thanks a lot Brian!

I upgraded to go version go1.14.3 linux/amd64 in Ubuntu 20.04 LTS and now 
the problem is gone. thx!

On Saturday, July 25, 2020 at 12:25:15 PM UTC-4, Brian Candler wrote:
>
> Works fine for me.  Inside an empty directory:
>
> $ wget 
> https://raw.githubusercontent.com/mkideal/cli/master/_examples/015-file/main.go
> $ go mod init github.com/mkideal/cli/015-file
> go: creating new go.mod: module github.com/mkideal/cli/015-file
> $ go build
> go: finding module for package github.com/mkideal/cli/ext
> go: finding module for package github.com/mkideal/cli
> go: downloading github.com/mkideal/cli v0.2.2
> go: found github.com/mkideal/cli in github.com/mkideal/cli v0.2.2
> go: downloading github.com/mkideal/pkg v0.1.2
> go: downloading github.com/labstack/gommon v0.3.0
> go: downloading github.com/mattn/go-isatty v0.0.12
> go: downloading github.com/mattn/go-colorable v0.1.7
> go: downloading golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd
> go: downloading golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
> $ go version
> go version go1.14.5 linux/amd64
> $ 
>

-- 
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/8054b55c-6678-40c9-885a-72f65679ca5bo%40googlegroups.com.


[go-nuts] go module @latest found but does not contain package

2020-07-24 Thread Tong Sun
Hi, 

How to get around the following, go module @latest found but does not 
contain package? 

$ cd /tmp/015-file

$ GO111MODULE=on

$ go mod init github.com/mkideal/cli/015-file
go: creating new go.mod: module github.com/mkideal/cli/015-file

$ cat go.mod module github.com/mkideal/cli/015-file

go 1.14

$ go build
go: finding module for package github.com/mkideal/cli
go: finding module for package github.com/mkideal/cli/ext
main.go:6:2: module github.com/mkideal/cli@latest found (v0.2.2), but does not 
contain package github.com/mkideal/cli
main.go:7:2: module github.com/mkideal/cli@latest found (v0.2.2), but does not 
contain package github.com/mkideal/cli/ext

$ go get -v github.com/mkideal/cli
go: github.com/mkideal/cli upgrade => v0.2.2

$ go get -v ./...
go: finding module for package github.com/mkideal/cli
go: finding module for package github.com/mkideal/cli/ext
go: finding module for package github.com/mkideal/cli
go: finding module for package github.com/mkideal/cli/ext
main.go:6:2: module github.com/mkideal/cli@latest found (v0.2.2), but does not 
contain package github.com/mkideal/cli
main.go:7:2: module github.com/mkideal/cli@latest found (v0.2.2), but does not 
contain package github.com/mkideal/cli/ext

$ go version
go version go1.14.1 linux/amd64


This is under Ubuntu 20.04.

-- 
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/335986d7-9e28-43ca-9489-35e776e5576fo%40googlegroups.com.


[go-nuts] Go Present slide syntax supported by talks.godoc.org

2020-07-22 Thread Tong Sun
Hi, 

I want to use the new Markdown Syntax instead of the old Legacy Present 
Syntax when writing my new Go Present slides. 

However I found that the new Markdown Syntax is not supported by 
talks.godoc.org yet, right? 

E.g., for the new Markdown Syntax Go Present slide at 
https://github.com/suntong/lang/blob/master/lang/Go/src/slides/subsection-test/subsection-markdown.slide

The corresponding 
https://talks.godoc.org/github.com/suntong/lang/lang/Go/src/slides/subsection-test/subsection-markdown.slide
 only 
gives me:

Internal server error.



Any recent plan to upgrade? Thx. 

-- 
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/de56b631-814e-4b31-a1a4-deb9f368b98fo%40googlegroups.com.


[go-nuts] Updating golang.org/x/tools

2020-02-16 Thread Tong Sun
Hi, 

My present from golang.org/x/tools is too old to be functioning properly:

$ present
2020/02/16 18:13:07 Failed to parse templates: template: slides.tmpl:65: 
function "pagenum" not defined


So I did `go get -v -u golang.org/x/tools`. However, my present is not 
updated and still giving me above error. 
(`type present` shows it is at $GOPATH/bin/present).

Wouldn't `go get` will install those binaries automatically? Or, how can I 
do that? (I had to build & cp manually to make my present working)

Here is full log of my `go get`:

$ go get -v -u golang.org/x/tools
Fetching https://golang.org/x/tools?go-get=1
Parsing meta tags from https://golang.org/x/tools?go-get=1 (status code 200)
get "golang.org/x/tools": found meta tag 
get.metaImport{Prefix:"golang.org/x/tools", VCS:"git", 
RepoRoot:"https://go.googlesource.com/tools"} at 
https://golang.org/x/tools?go-get=1
go: finding golang.org/x/tools latest
Fetching https://golang.org/x/net?go-get=1
Fetching https://golang.org/x/mod?go-get=1
Fetching https://golang.org/x/sync?go-get=1
Fetching https://golang.org/x/xerrors?go-get=1
Parsing meta tags from https://golang.org/x/net?go-get=1 (status code 200)
get "golang.org/x/net": found meta tag 
get.metaImport{Prefix:"golang.org/x/net", VCS:"git", 
RepoRoot:"https://go.googlesource.com/net"} at 
https://golang.org/x/net?go-get=1
Parsing meta tags from https://golang.org/x/mod?go-get=1 (status code 200)
get "golang.org/x/mod": found meta tag 
get.metaImport{Prefix:"golang.org/x/mod", VCS:"git", 
RepoRoot:"https://go.googlesource.com/mod"} at 
https://golang.org/x/mod?go-get=1
Parsing meta tags from https://golang.org/x/xerrors?go-get=1 (status code 
200)
get "golang.org/x/xerrors": found meta tag 
get.metaImport{Prefix:"golang.org/x/xerrors", VCS:"git", 
RepoRoot:"https://go.googlesource.com/xerrors"} at 
https://golang.org/x/xerrors?go-get=1
go: finding golang.org/x/net v0.0.0-20190620200207-3b0461eec859
go: finding golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898
Parsing meta tags from https://golang.org/x/sync?go-get=1 (status code 200)
get "golang.org/x/sync": found meta tag 
get.metaImport{Prefix:"golang.org/x/sync", VCS:"git", 
RepoRoot:"https://go.googlesource.com/sync"} at 
https://golang.org/x/sync?go-get=1
go: finding golang.org/x/sync v0.0.0-20190423024810-112230192c58
go: finding golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee
Fetching https://golang.org/x/crypto?go-get=1
Fetching https://golang.org/x/text?go-get=1
Fetching https://golang.org/x/sys?go-get=1
Parsing meta tags from https://golang.org/x/text?go-get=1 (status code 200)
get "golang.org/x/text": found meta tag 
get.metaImport{Prefix:"golang.org/x/text", VCS:"git", 
RepoRoot:"https://go.googlesource.com/text"} at 
https://golang.org/x/text?go-get=1
Parsing meta tags from https://golang.org/x/sys?go-get=1 (status code 200)
Parsing meta tags from https://golang.org/x/crypto?go-get=1 (status code 
200)
get "golang.org/x/sys": found meta tag 
get.metaImport{Prefix:"golang.org/x/sys", VCS:"git", 
RepoRoot:"https://go.googlesource.com/sys"} at 
https://golang.org/x/sys?go-get=1
get "golang.org/x/crypto": found meta tag 
get.metaImport{Prefix:"golang.org/x/crypto", VCS:"git", 
RepoRoot:"https://go.googlesource.com/crypto"} at 
https://golang.org/x/crypto?go-get=1
go: finding golang.org/x/sync latest
go: finding golang.org/x/xerrors latest
go: finding golang.org/x/net latest
go: finding golang.org/x/sys latest
go: finding golang.org/x/crypto latest
go: finding golang.org/x/mod v0.2.0
go: finding golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
go: finding golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e
go: finding golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
go: downloading golang.org/x/tools v0.0.0-20200216192241-b320d3a0f5a2
go: extracting golang.org/x/tools v0.0.0-20200216192241-b320d3a0f5a2
Fetching https://golang.org/x?go-get=1
Parsing meta tags from https://golang.org/x?go-get=1 (status code 200)
Fetching https://golang.org?go-get=1
Parsing meta tags from https://golang.org?go-get=1 (status code 200)


thanks

-- 
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/7866727f-2fa5-4e68-a032-7cc8e55b2790%40googlegroups.com.


[go-nuts] benchgraph: no data to show

2019-12-06 Thread Tong Sun
Oh, yeah, that's perfect. 

However, anyone get it working? 

I think I'm following the instruction correctly, however, whatever I tried, 
I always get no data to show error. I use benchgraph from latest git. 

Anyone able to get benchgraph from latest git working? 

Thx.


On Friday, December 6, 2019 at 3:14:57 PM UTC-5, Sean Liao wrote:
>
> not sure if this fits https://github.com/codingberg/benchgraph
>
>
> On Friday, December 6, 2019 at 2:21:47 AM UTC+1, Tong Sun wrote:
>>
>> Hi, 
>>
>> Any existing tools out there that can turn Go's benchmark result from 
>> text into chart? 
>>
>> I'm looking for a simple/light-weighted solution, like using gnuplot, or 
>> web --
>> Found one using Python to plot Go's benchmark result, but don't like the 
>> overhead. 
>>
>> thx
>>
>>

-- 
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/085ed5e6-e12a-4000-87dc-97c14fdbe3fe%40googlegroups.com.


[go-nuts] Re: [ANN] Arhat: an experimental deep learning framework implemented in Go

2019-12-05 Thread Tong Sun


On Monday, December 2, 2019 at 12:56:14 PM UTC-5, Alexey wrote:
>
> I would like to announce the first public release of Arhat, an 
> experimental deep learning framework implemented in Go.
>
> Unlike most mainstream frameworks that perform training and inference 
> computations directly, Arhat translates neural network descriptions into 
> standalone lean executable platform-specific code. 
>

That's a super good idea. Just curious, what type of neural network 
descriptions input does it take?
 

> This approach allows direct embedding of the generated code into user 
> applications and does not require deployment of sophisticated machine 
> learning software stacks on the target platforms.
>
> We at Fragata use Arhat as a research platform for our larger ongoing 
> project aiming at construction of a production-grade machine learning 
> framework optimized for use on embedded platforms and massively parallel 
> supercomputers.
>
> The project repository is located here:
>
> https://github.com/fragata-ai/arhat
>
>
>

-- 
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/e339b818-023f-45cf-aa32-ff4f41b18b2e%40googlegroups.com.


[go-nuts] Re: Is a public go benchmarking database/dashboard available

2019-12-05 Thread Tong Sun


On Monday, December 2, 2019 at 10:33:25 PM UTC-5, Xiangdong JI wrote:
>
> Hi,
>
> Wondering if there is any public database/dashboard of Go's benchmarking 
> data available? Thanks.
>

And by "public database" you meant a central one that covers everything? 
I.e., the purpose of benchmarking varies dramatically, please elaborate why 
you would think a cover-it-all one is a good idea. 


-- 
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/035f11da-b932-4f98-b753-b258684652c6%40googlegroups.com.


[go-nuts] Plot Go's benchmark result

2019-12-05 Thread Tong Sun
Hi, 

Any existing tools out there that can turn Go's benchmark result from text 
into chart? 

I'm looking for a simple/light-weighted solution, like using gnuplot, or 
web --
Found one using Python to plot Go's benchmark result, but don't like the 
overhead. 

thx

-- 
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/c737f2d5-cc55-4ddc-a905-9c443d3916c8%40googlegroups.com.


Re: [go-nuts] Pointer to the loop variable

2019-09-10 Thread Tong Sun


On Tuesday, September 10, 2019 at 3:18:47 PM UTC-4, burak serdar wrote:
>
> On Tue, Sep 10, 2019 at 1:13 PM Tong Sun > 
> wrote: 
> > 
> > I'm experiencing a weird problem with my program and finally nail it 
> down to what exactly went wrong, so that I can write a minimum program to 
> duplicate it. See the following program: 
> > 
> > package main 
> > 
> > 
> > import ( 
> >  "fmt" 
> > ) 
> > 
> > 
> > type Vertex struct { 
> >  X int 
> >  Y int 
> > } 
> > 
> > 
> > func main() { 
> >  vs := []Vertex{ 
> >  Vertex{1, 2}, // has type Vertex 
> >  Vertex{X: 3}, // Y:0 is implicit 
> >  Vertex{}, // X:0 and Y:0 
> >  } 
> > 
> > 
> >  fmt.Printf("Vertex Slice %+v\n", vs) 
> >  var vp *Vertex = nil 
> >  for _, v := range vs { 
> >  if v.X == 3 { 
> >  vp =  
> >  } 
> >  } 
> >  fmt.Printf("Found: %+v\n", vp) 
> > } 
> > 
> > 
> > https://play.golang.org/p/R645C5plojx 
> > 
> > I was expecting that the found Vertex is "v.X == 3", however the result 
> is not. 
>
> Because you're keeping a pointer to the loop variable. v continues 
> changing after you store the address of it, so you get the latest 
> value of v. Instead, save a copy of v, or break the loop as soon as 
> what you're looking for is found: 
>

 I can't break the loop immediately as my not-minimized real program use a 
double loop to find the *closest *item. That's the reason I using the 
pointer to track my finding...

if v.x==3 { 
>t:=v 
>vp= 
> } 
>

 OK. will do that. thx

> 
> > - what exactly is causing the problem? 
> > - how to fix it so that I got what I was looking for? 
> > 
> > Again, the snip is at 
> > https://play.golang.org/p/R645C5plojx 
> > 
> > Thanks 
> > 
> > -- 
> > 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 golan...@googlegroups.com . 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/143205c1-2c86-4404-94d2-4182a6285e21%40googlegroups.com.
>  
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/6d0d6a78-fe02-445c-bacd-29b205e05175%40googlegroups.com.


[go-nuts] Pointer to the loop variable

2019-09-10 Thread Tong Sun
I'm experiencing a weird problem with my program and finally nail it down 
to what exactly went wrong, so that I can write a minimum program to 
duplicate it. See the following program:

package main


import (
 "fmt"
)


type Vertex struct {
 X int
 Y int
}


func main() {
 vs := []Vertex{
 Vertex{1, 2}, // has type Vertex
 Vertex{X: 3}, // Y:0 is implicit
 Vertex{}, // X:0 and Y:0
 }


 fmt.Printf("Vertex Slice %+v\n", vs)
 var vp *Vertex = nil
 for _, v := range vs {
 if v.X == 3 {
 vp = 
 }
 }
 fmt.Printf("Found: %+v\n", vp)
}


https://play.golang.org/p/R645C5plojx

I was expecting that the found Vertex is "v.X == 3", however the result is 
not. 

- what exactly is causing the problem?
- how to fix it so that I got what I was looking for? 

Again, the snip is at
https://play.golang.org/p/R645C5plojx

Thanks

-- 
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/143205c1-2c86-4404-94d2-4182a6285e21%40googlegroups.com.


[go-nuts] Wrapper package for dialog (and Xdialog)?

2019-08-11 Thread Tong Sun
Hi, 

I know there are several ncurses based wrapper packages (like goncurses), 
but are there any wrapper packages out there dialog (and Xdialog), or 
something similar? The goncurses is still too low-level for my 
simple dialog-base requirement/use. 

thx

-- 
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/54e957d6-3a5a-44f0-b8e7-a0cb74a7dacc%40googlegroups.com.


Re: [go-nuts] Preparing defaults for multiple-values-returning functions

2019-07-22 Thread Tong Sun


On Monday, July 22, 2019 at 2:59:33 PM UTC-4, Burak Serdar wrote:
>
> On Mon, Jul 22, 2019 at 12:51 PM Tong Sun  > wrote: 
> > 
> > I want to define a default set of values for the 
> multiple-values-returning function, so when doing error checking along the 
> way, I can return such default set when things go wrong. 
> > 
> > How can I do that? 
> > Is it possible to make the 17&18 line of the following working? 
> > https://play.golang.org/p/OX6QwWXc2ch 
>
> https://play.golang.org/p/_U4CvzTBxkX 
>


Ah, bingo! This is much better than the "goto return_defaults" solution in 
my view. THX a lot!

 

>
> > 
> > thx 
> > 
> > -- 
> > 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 golan...@googlegroups.com . 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/b74868fc-65a0-4b04-a898-411139b3b9f8%40googlegroups.com.
>  
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/461b3039-182d-4796-9491-3da131871363%40googlegroups.com.


[go-nuts] Preparing defaults for multiple-values-returning functions

2019-07-22 Thread Tong Sun
I want to define a default set of values for the multiple-values-returning 
function, so when doing error checking along the way, I can return such 
default set when things go wrong.

How can I do that? 
Is it possible to make the 17&18 line of the following working?
https://play.golang.org/p/OX6QwWXc2ch

thx

-- 
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/b74868fc-65a0-4b04-a898-411139b3b9f8%40googlegroups.com.


[go-nuts] Variable life time -- sql.DB connection defer closing question

2019-07-22 Thread Tong Sun
All SQL DB statements need a sql.DB connection:

var conn *sql.DB = ...
defer conn.Close()

statement, err := conn.Prepare(SQL)


My question is, if I want to reuse the `conn` variable later on in the same 
function, 

conn, err = sql.Open("mssql", NewConnString)


Do I need to put another `defer conn.Close()` after it, or the first `defer 
conn.Close()` still applies? Or I should call `conn.Close()` explicitly 
beforehand? 

thanks

-- 
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/11c35ccc-0713-4e09-8325-a4e608758b15%40googlegroups.com.


Re: [go-nuts] Re: Go will shine on huge web projects, but how about simple ones?

2019-06-13 Thread Tong Sun
Hi Damian & all.

I think I need to set the record straight, as most of the technical
discussions has been taken place elsewhere, so I feel that I was treated
unfairly because of that. If you only see one site of the story, then it is
very easy to do that, I get it and understand it however.

So first of all, was I *"like Perl and think it performs good enough or
better for your use"*? No. As I have expressed again and again, I don't
think Go should lag so far behind of Perl. How bad? See for yourself:

[image: image.png]

There has some discrepancies and discussions on Apache Bench's statistics,
but my conclusion was that I trust the measured & reported response time
more than the statistical numbers.

This is the fundamental of the discussion. And as I have expressed again
and again, I want to improve my Go code, because I don't think Go being 8
times longer than (that *"ridiculously simple")* Perl on average, *"its
results are totally unsurprising"* and should be an accepted as an
*unchangeable
fact*.

So if you had thought I should be the one who apologies first, expressed on
or off line, please read on...

On Mon, Jun 10, 2019 at 7:50 PM Axel Wagner wrote:

>
> On Mon, Jun 10, 2019 at 11:28 PM Tong Sun wrote:
>
>> There is a second test well before your this post, which is a direct
>> translation of Perl code, that is now reading and writing directly to
>> a socket. Hanging on to the first test method and not referring to the
>> second test is not a very constructive way of discussion, let alone
>> using words like "ridiculously ...".
>>
>
> The updated test only changes *both* not to implement a web server. My
> point was, that this is not a realistic test case.e
>
>
>> Over 90% of the code are NOT doing regular expression matching.
>> Focusing *only* on regular expression, not >90% of the rest, is not
>> very convincing but miss the elephant in the room, at least seems to
>> me.
>
>
> The amount of SLOC is not important, however, but where time is spent.
> When adding some basic CPU profiling to the Go code, it spent ~10% of its
> time RE-matching, ~10% in various allocation-related activities, ~75%
> blocking in syscalls and the rest in other various network related runtime
> code. That's pretty much what I meant - in terms of actual CPU time used,
> RE-matching (and some allocation) is pretty much all that's happening. Now,
> I don't know how to profile Perl code and I'll admit that the netpoller
> etc. are part of the language and as such matter for the comparison. But
> the more direct the translation becomes, the less these code-paths will
> differ in performance and the more realistic your scenario gets (in terms
> of concurrency used and required), the more I'd expect Go to be favored by
> it.
>
> Please don't get personal and emotional over technical discussions,
>> and please refrain from using terms like "ridiculously simple" or
>> "reading in tea-leafs" in future discussions. It is inappropriately
>> condescending, thus not the correct attitude of communication.  It
>> does not align with the code of conduct of this mlist, and neither of
>> google's, I believe.
>>
>> If you have test results that contradict with mine, please show me
>> yours -- Let's talk the data, and not let the emotion get in the way
>> of technical discussion, and fact the fact, whatever it is.
>
>
There is a reason I'm saying above. Here I quote word for word from Axel
Wagner:

In any case, in this direct translation, I would've actually assumed perl
> to be faster - because literally all we do is a regexp-match and the perl
> RE-engine is famously optimized and the Go RE-engine is famously meh. That
> perl still ends up with significantly higher average response times is…
> honestly, a confirmation that it's not a very fast language.
>


> BTW, I also used a different tool to benchmark (github.com/rakyll/hey).
> AIUI, it uses multiple cores more efficiently. With that tool, the perl
> implementation gets absolutely demolished, with an average response time
> ~40x higher than the Go implementation on my machine.


I tried out his implementation eagerly (after thank him publicly of
course), but my result cannot replicate his findings/claims. So I asked him
a follow up question in the blog. He never replies to my inquiry, and now
is this, the only reply I get, from my simple *technical *question, "As you
can see, the test result from my machine is much different from yours.
Would you blog how you tested and your results please?"

I am not contradicting your data, I'm contradicting your conclusions.
>

And now he changed his tune. I never accused him of *"reading tea-leafs"*
for coming up the ungrounded conc

Re: [go-nuts] Re: Go will shine on huge web projects, but how about simple ones?

2019-06-12 Thread Tong Sun
Yeah, no doubt, I totally agree with that as well.

But now, I can proudly say ...

My Go beats C :-)

On Thu, Jun 13, 2019 at 12:09 AM Justin Israel  wrote:
>
>
>
> On Thu, Jun 13, 2019 at 4:05 PM Tong Sun  wrote:
>>
>> Yep, thanks Justin, both your points really made the difference,
>> because I do believe that the buffered socket write is the key
>> component for the 3-time improvement that I'm getting (from using
>> FastHTTP), IMHO. And FastHTTP recommends GOMAXPROCS=1 too, which I
>> used this time as well.
>>
>> So thanks again, Justin & Ronny!
>
>
> Cool. Glad that actually helped. I do feel with your results, and in 
> agreement with others,  that you really are comparing Go to the underlying C 
> implementation of php, with everything stripped back so far. But at least you 
> are happy with your results!
>
>>
>> On Sat, Jun 8, 2019 at 10:54 PM Justin Israel  wrote:
>> >
>> > I'm wondering about a couple factors in this comparison that seem to make 
>> > a difference in my local test:
>> >
>> > I think perl sockets are write buffered. So would the equivalent be to 
>> > wrap the net.Conn in bufio.NewWriter(c) and flush before the Close?
>> > Since this is a straigh-line test where both servers are not using 
>> > concurrent handling of connections (uncommon for a Go server even on 1 
>> > core), would it not make sense to run the Go server with GOMAXPROCS=1?
>> >
>> > - Justin
>> >
>> > On Saturday, June 8, 2019 at 1:36:49 AM UTC+12, Tong Sun wrote:
>> >>
>> >> I had always believed that the web projects build with Go should be much 
>> >> faster than Perl, since Go is a compiled language.
>> >>
>> >> However that belief was crushed brutally last night, when I did a 
>> >> comparison -- the Go implementation is 8 times worse than the Perl! -- 
>> >> the mean response time jumped from 6ms to 48ms.
>> >>
>> >> I know this is the simplest possible web server, but still, when it comes 
>> >> to simple web servers like this, I have to say that Perl performs much 
>> >> better than Go.
>> >>
>> >> I don't think there is much I can twist on the Go side, since it can't be 
>> >> more simpler than that. However, I also believe it won't hurt to ask and 
>> >> confirm. So,
>> >>
>> >> Have I missed anything? Is it possible for me to make my Go 
>> >> implementation anywhere near the Perl's performance?
>> >>
>> >> Thanks
>> >>
>> >>
>> > --
>> > You received this message because you are subscribed to a topic in the 
>> > Google Groups "golang-nuts" group.
>> > To unsubscribe from this topic, visit 
>> > https://groups.google.com/d/topic/golang-nuts/iH2Ck_hpCpI/unsubscribe.
>> > To unsubscribe from this group and all its topics, 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/37a1ac7e-85ee-4775-b348-5673c41a162c%40googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.

-- 
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/CAMmz1OfyK5n7JyMy8MmL3ikB1mAdHtp1d1EZ_s269nHfZxxKEA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Go will shine on huge web projects, but how about simple ones?

2019-06-12 Thread Tong Sun
Yep, thanks Justin, both your points really made the difference,
because I do believe that the buffered socket write is the key
component for the 3-time improvement that I'm getting (from using
FastHTTP), IMHO. And FastHTTP recommends GOMAXPROCS=1 too, which I
used this time as well.

So thanks again, Justin & Ronny!

On Sat, Jun 8, 2019 at 10:54 PM Justin Israel  wrote:
>
> I'm wondering about a couple factors in this comparison that seem to make a 
> difference in my local test:
>
> I think perl sockets are write buffered. So would the equivalent be to wrap 
> the net.Conn in bufio.NewWriter(c) and flush before the Close?
> Since this is a straigh-line test where both servers are not using concurrent 
> handling of connections (uncommon for a Go server even on 1 core), would it 
> not make sense to run the Go server with GOMAXPROCS=1?
>
> - Justin
>
> On Saturday, June 8, 2019 at 1:36:49 AM UTC+12, Tong Sun wrote:
>>
>> I had always believed that the web projects build with Go should be much 
>> faster than Perl, since Go is a compiled language.
>>
>> However that belief was crushed brutally last night, when I did a comparison 
>> -- the Go implementation is 8 times worse than the Perl! -- the mean 
>> response time jumped from 6ms to 48ms.
>>
>> I know this is the simplest possible web server, but still, when it comes to 
>> simple web servers like this, I have to say that Perl performs much better 
>> than Go.
>>
>> I don't think there is much I can twist on the Go side, since it can't be 
>> more simpler than that. However, I also believe it won't hurt to ask and 
>> confirm. So,
>>
>> Have I missed anything? Is it possible for me to make my Go implementation 
>> anywhere near the Perl's performance?
>>
>> Thanks
>>
>>
> --
> You received this message because you are subscribed to a topic in the Google 
> Groups "golang-nuts" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/golang-nuts/iH2Ck_hpCpI/unsubscribe.
> To unsubscribe from this group and all its topics, 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/37a1ac7e-85ee-4775-b348-5673c41a162c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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/CAMmz1OdcaBxZV2fOBu6hR1EdoE2JF8Vprgj1s9rOapAhwv8BEQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Go will shine on huge web projects, but how about simple ones?

2019-06-12 Thread Tong Sun
On Mon, Jun 10, 2019 at 5:27 PM Tong Sun wrote:

> > IMO this is just not a meaningful test. Or its results are totally 
> > unsurprising.
>
> Again, I was trying to improve Perl performs with Go. That
> "ridiculously simple" Perl code is the foundation of the Debian dbab
> package, and I was trying to improve it.
>
> It might be meaningless to you but it is perfectly meaningful to me.

For those who care ... long story short, I finally made it, with helps
I got from various sources -- I finally made Go faster than Perl!
https://dev.to/suntong/simple-web-server-in-perl-and-go-finally-1kgh

-- 
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/CAMmz1Od51Cgqw6NE7DwodHT0NNfVvJwt60g6ri3EVKN3crX9qw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Go will shine on huge web projects, but how about simple ones?

2019-06-11 Thread Tong Sun
Thanks Amnon for the insight, which confirmed my guessing when
answering the following question against ab in my blog:

> I'm unclear how to interpret the results from ab. From the top chunk of the 
> results (time taken for tests, requests per second, time per request, etc.), 
> it would appear that Go is about 33% faster than Perl. But the bit at the 
> bottom about "percentage of the requests served..." seems wildly incongruent 
> and makes it look like Perl is orders of magnitude faster. It doesn't add up. 
> It also doesn't logically add up for Perl to be faster than Go (which, I get, 
> is your point). It makes me suspicious of ab's results.

On Tue, Jun 11, 2019 at 7:44 AM Amnon Baron Cohen  wrote:
>
> For those interested, you can find some web benchmarks here 
> https://www.techempower.com/benchmarks/
>
> For the trivial http ping type server, you would expect latency to be 
> dominated by system time.
> strace'ing your code will give you an idea what it is doing. Go allows you to 
> have multiple goroutines
> serving responses. This does carry a certain overhead as any network reads 
> will have to go through
> netpoll to demux and schedule goroutines when the packets they are waiting 
> for arrives.
> So we should not be too dismayed if Go code shows higher latencies than a 
> single treaded script.
>
> --
> You received this message because you are subscribed to a topic in the Google 
> Groups "golang-nuts" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/golang-nuts/iH2Ck_hpCpI/unsubscribe.
> To unsubscribe from this group and all its topics, 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/d091d5a4-afdc-4538-b86c-fe6fa6b99ccf%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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/CAMmz1Of3AvAK05PbJ%2B3Ri_QSaEfFqPBE3b%3Dfk-U_xXRn7QJXpA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Go will shine on huge web projects, but how about simple ones?

2019-06-10 Thread Tong Sun
StatusOK, "image/gif", pixelBuf)
>>}
>>e.GET("*", servePixel)
>>
>>// Start server
>>e.Logger.Fatal(e.Start(fmt.Sprintf("0.0.0.0:%d", *port)))
>> }
>>
>>
>>
>> On Mon, Jun 10, 2019 at 4:07 PM Marcin Romaszewicz  wrote:
>>>
>>> I think the others were correct in pointing the finger at the RegEx engine 
>>> in Go. It is quite slow. I hacked your inside loop which checks the request 
>>> not to use regular expressions, and it's tons faster. You can't say that 
>>> something can't be responsible for too much slowdown because it "1 line", 
>>> since that one line has a lot of weight behind it. Using regular 
>>> expressions, a benchmark showed 1782 requests per second. Using my simple 
>>> hack, it's 18827 per second. Let's call it 10x faster.
>>>
>>> if strings.Contains(line, "HTTP") {
>>>parts := strings.Split(line, " ")
>>>req.Method = strings.ToUpper(strings.TrimSpace(parts[0]))
>>>req.URL = strings.ToUpper(strings.TrimSpace(parts[1]))
>>>req.Version = strings.ToUpper(strings.TrimSpace(parts[2]))
>>>continue
>>> }
>>>
>>>
>>> For this benchmark it behaves correctly, I realize this is fragile. I ran 
>>> `ab -n 1 -c 100...` to run the tests.
>>>
>>> Benchmarks using regular expressions:
>>> Concurrency Level:  100
>>> Time taken for tests:   5.610 seconds
>>> Complete requests:  1
>>> Failed requests:0
>>> Total transferred:  179 bytes
>>> HTML transferred:   43 bytes
>>> Requests per second:1782.41 [#/sec] (mean)
>>> Time per request:   56.104 [ms] (mean)
>>> Time per request:   0.561 [ms] (mean, across all concurrent requests)
>>> Transfer rate:  311.57 [Kbytes/sec] received
>>>
>>> Connection Times (ms)
>>>   min  mean[+/-sd] median   max
>>> Connect:0   46 352.7  83557
>>> Processing: 0   10  10.6  8 158
>>> Waiting:0   10  10.6  8 158
>>> Total:  0   56 352.5 213565
>>>
>>> Percentage of the requests served within a certain time (ms)
>>>   50% 21
>>>   66% 24
>>>   75% 24
>>>   80% 24
>>>   90% 25
>>>   95% 26
>>>   98%164
>>>   99%   3549
>>>  100%   3565 (longest request)
>>>
>>> Benchmarks using my hack:
>>>
>>> Concurrency Level:  100
>>> Time taken for tests:   0.531 seconds
>>> Complete requests:  1
>>> Failed requests:0
>>> Total transferred:  179 bytes
>>> HTML transferred:   43 bytes
>>> Requests per second:18827.39 [#/sec] (mean)
>>> Time per request:   5.311 [ms] (mean)
>>> Time per request:   0.053 [ms] (mean, across all concurrent requests)
>>> Transfer rate:  3291.12 [Kbytes/sec] received
>>>
>>> Connection Times (ms)
>>>   min  mean[+/-sd] median   max
>>> Connect:03   0.3  3   4
>>> Processing: 13   0.4  3   5
>>> Waiting:03   0.4  3   5
>>> Total:  35   0.5  5   8
>>>
>>> Percentage of the requests served within a certain time (ms)
>>>   50%  5
>>>   66%  5
>>>   75%  5
>>>   80%  5
>>>   90%  6
>>>   95%  6
>>>   98%  7
>>>   99%  7
>>>  100%  8 (longest request)
>>>
>>>
>>> On Mon, Jun 10, 2019 at 2:28 PM Tong Sun  wrote:
>>>>
>>>> Just to clarify some facts.
>>>>
>>>> On Sun, Jun 9, 2019 at 11:09 AM 'Axel Wagner' wrote:
>>>> >
>>>> > As I've also mentioned: I don't think this test is meaningful.
>>>> >
>>>> > First, as it has been pointed out, your Perl program isn't actually a 
>>>> > web server. It only understands ridiculously simple requests and as such 
>>>> > violates the spec left and right. It's also super naive in how it treats 
>>>> > malformed input or actively malicious clients - all of which are handled 
>>>> > by the Go http package, so of course it's going to have some overhead.
>>>>
>>>> There is a second test well before your this post, which is a direct
>>>&g

Re: [go-nuts] Re: Go will shine on huge web projects, but how about simple ones?

2019-06-10 Thread Tong Sun
On Mon, Jun 10, 2019 at 7:50 PM Axel Wagner
 wrote:
>
>
>
> On Mon, Jun 10, 2019 at 11:28 PM Tong Sun  wrote:
>>
>> There is a second test well before your this post, which is a direct
>> translation of Perl code, that is now reading and writing directly to
>> a socket. Hanging on to the first test method and not referring to the
>> second test is not a very constructive way of discussion, let alone
>> using words like "ridiculously ...".
>
>
> The updated test only changes *both* not to implement a web server. My point 
> was, that this is not a realistic test case.e
>
>>
>> Over 90% of the code are NOT doing regular expression matching.
>> Focusing *only* on regular expression, not >90% of the rest, is not
>> very convincing but miss the elephant in the room, at least seems to
>> me.
>
>
> The amount of SLOC is not important, however, but where time is spent. When 
> adding some basic CPU profiling to the Go code, it spent ~10% of its time 
> RE-matching, ~10% in various allocation-related activities, ~75% blocking in 
> syscalls and the rest in other various network related runtime code. That's 
> pretty much what I meant - in terms of actual CPU time used, RE-matching (and 
> some allocation) is pretty much all that's happening. Now, I don't know how 
> to profile Perl code and I'll admit that the netpoller etc. are part of the 
> language and as such matter for the comparison. But the more direct the 
> translation becomes, the less these code-paths will differ in performance and 
> the more realistic your scenario gets (in terms of concurrency used and 
> required), the more I'd expect Go to be favored by it.
>
>> Please don't get personal and emotional over technical discussions,
>> and please refrain from using terms like "ridiculously simple" or
>> "reading in tea-leafs" in future discussions. It is inappropriately
>> condescending, thus not the correct attitude of communication.  It
>> does not align with the code of conduct of this mlist, and neither of
>> google's, I believe.
>>
>> If you have test results that contradict with mine, please show me
>> yours -- Let's talk the data, and not let the emotion get in the way
>> of technical discussion, and fact the fact, whatever it is.
>
>
> I am not contradicting your data, I'm contradicting your conclusions. That's 
> why I said "reading tea-leafs": You seem to look at the same data and come to 
> conclusions that just don't connect for me. For example, your original post 
> says that the mean response time for your Perl code is 110.875ms resp. 
> 0.222ms and for your Go code it's 83.229ms resp. 0.166ms - and yet you claim 
> that your test shows that the mean response time is 8x higher for your Go 
> code than your Perl code.
>
> And in your second post, you use `hey`, but then just… throw the results out, 
> because you don't understand them (AIUI).
>
> I just don't know how I'm supposed to handle that discrepancy. All of this 
> just looks like really bad science to me. ISTM that defining the criteria 
> beforehand and designing the test to measure exactly those criteria is the 
> most reasonable way to reconcile that. If we use "mean response time over X", 
> it seems that so far your Go code is coming out ahead. And note that *I* 
> didn't make any claims about the relative strengths of programming languages 
> here. IMO the onus is clearly on you to show your work when making these 
> claims. I don't actually care.

I think you should at least try to apologize for your rude behavior,
but again you are ignoring all others' valid reasoning and concluding
your make sense while others don't.

That's a very good point to end the discussion.
I'll not be responding to your trolls.

>> > Anyway, all of that being said: While I don't think the test you devised 
>> > allows the broad generalizations you are making, ultimately I don't have 
>> > any stakes in this (which is why I haven't responded further on the blog 
>> > post). If you like Perl and think it performs good enough or better for 
>> > your use case - then go ahead and use Perl. No one here will begrudge you 
>> > for it.
>>
>> As I've comment in the blog many times, I'm not trying to prove Perl
>> performs better than Go. On the contrary, I was trying to improve Perl
>> performs with Go, that's why the whole thing get started, as I have
>> replied to your comment in the blog:"that's why I was rewriting the
>> Perl code to Go".
>>
>> It is still the case, and I want to try out everyone's suggestion to
>> see how things can improve.
>>
>> Moreover, if

Re: [go-nuts] Re: Go will shine on huge web projects, but how about simple ones?

2019-06-10 Thread Tong Sun
 to me.
Please don't be so judgmental.

> On Sun, Jun 9, 2019 at 4:54 AM Justin Israel  wrote:
>>
>> I'm wondering about a couple factors in this comparison that seem to make a 
>> difference in my local test:
>>
>> I think perl sockets are write buffered. So would the equivalent be to wrap 
>> the net.Conn in bufio.NewWriter(c) and flush before the Close?
>> Since this is a straigh-line test where both servers are not using 
>> concurrent handling of connections (uncommon for a Go server even on 1 
>> core), would it not make sense to run the Go server with GOMAXPROCS=1?
>>
>> - Justin
>>
>> On Saturday, June 8, 2019 at 1:36:49 AM UTC+12, Tong Sun wrote:
>>>
>>> I had always believed that the web projects build with Go should be much 
>>> faster than Perl, since Go is a compiled language.
>>>
>>> However that belief was crushed brutally last night, when I did a 
>>> comparison -- the Go implementation is 8 times worse than the Perl! -- the 
>>> mean response time jumped from 6ms to 48ms.
>>>
>>> I know this is the simplest possible web server, but still, when it comes 
>>> to simple web servers like this, I have to say that Perl performs much 
>>> better than Go.
>>>
>>> I don't think there is much I can twist on the Go side, since it can't be 
>>> more simpler than that. However, I also believe it won't hurt to ask and 
>>> confirm. So,
>>>
>>> Have I missed anything? Is it possible for me to make my Go implementation 
>>> anywhere near the Perl's performance?
>>>
>>> Thanks
>>>
>>>
>> --
>> 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/37a1ac7e-85ee-4775-b348-5673c41a162c%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the Google 
> Groups "golang-nuts" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/golang-nuts/iH2Ck_hpCpI/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAEkBMfF62D5v%2BRiGtAtzuH0wAHzCLqcwNUidC1Oe2KN9DfRv6Q%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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/CAMmz1OcefkrZN3_5R7%2BbjuwHjRx%2BLzttaiXmer0ytwmXUjxN_A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Go will shine on huge web projects, but how about simple ones?

2019-06-08 Thread Tong Sun
On Sat, Jun 8, 2019 at 3:01 PM Wojciech S. Czarnecki  wrote:
>
> On Sat, 8 Jun 2019 09:56:05 -0400
> Tong Sun  wrote:
>
> > Agree that it was not an apples to apples comparison. So please check
> > out my 2nd blog:
> >
> > https://dev.to/suntong/simple-web-server-in-perl-and-go-revisit-5d82
> >
>
> Trying to make sense of your measures...
>
> ...Still apples to oranges due to testing on a loopback interface. Both ab 
> and perl are wired up to the kernel short paths
> so in fact their packets were exchanged via a simple ownership change (of the 
> block of memory).
> AFAIK bytes from packets destined to go server were copied as go does not 
> link to glibc for net support
> (it does it only for nslookup services).
>
> Try to benchmark **over real wire**.
>
> Also use more tools: https://github.com/httperf/httperf, even old Siege.
> Read 
> https://www.nginx.com/blog/testing-the-performance-of-nginx-and-nginx-plus-web-servers/
> how their tests were done.

Thanks.

So I benchmarked over real wire, using httperf. But seems to me
httperf is not reporting much, right?
At least not to the level you refered as "how their tests were done".

Anyway, apart from the following, what else can I get out of httperf?


$ httperf --server 192.168.0.11 --port  --uri / --num-conns 1500 --hog
httperf --hog --client=0/1 --server=192.168.0.11 --port= --uri=/
--send-buffer=4096 --recv-buffer=16384 --num-conns=1500 --num-calls=1
httperf: warning: open file limit > FD_SETSIZE; limiting max. # of
open files to FD_SETSIZE
Maximum connect burst length: 1

Total: connections 1500 requests 1500 replies 1500 test-duration 1.325 s

Connection rate: 1132.2 conn/s (0.9 ms/conn, <=1 concurrent connections)
Connection time [ms]: min 0.4 avg 0.9 max 3.5 median 0.5 stddev 0.2
Connection time [ms]: connect 0.4
Connection length [replies/conn]: 1.000

Request rate: 1132.2 req/s (0.9 ms/req)
Request size [B]: 65.0

Reply rate [replies/s]: min 0.0 avg 0.0 max 0.0 stddev 0.0 (0 samples)
Reply time [ms]: response 0.4 transfer 0.1
Reply size [B]: header 136.0 content 43.0 footer 0.0 (total 179.0)
Reply status: 1xx=0 2xx=1500 3xx=0 4xx=0 5xx=0

CPU time [s]: user 0.32 system 1.00 (user 24.4% system 75.5% total 99.8%)
Net I/O: 269.8 KB/s (2.2*10^6 bps)

Errors: total 0 client-timo 0 socket-timo 0 connrefused 0


The above is Go.
The following is Perl.

$ httperf --server 192.168.0.10 --uri / --num-conns 1500 --hog
httperf --hog --client=0/1 --server=192.168.0.10 --port=80 --uri=/
--send-buffer=4096 --recv-buffer=16384 --num-conns=1500 --num-calls=1
httperf: warning: open file limit > FD_SETSIZE; limiting max. # of
open files to FD_SETSIZE
Maximum connect burst length: 1

Total: connections 1500 requests 1500 replies 1500 test-duration 1.285 s

Connection rate: 1167.6 conn/s (0.9 ms/conn, <=1 concurrent connections)
Connection time [ms]: min 0.3 avg 0.9 max 1.8 median 0.5 stddev 0.2
Connection time [ms]: connect 0.4
Connection length [replies/conn]: 1.000

Request rate: 1167.6 req/s (0.9 ms/req)
Request size [B]: 65.0

Reply rate [replies/s]: min 0.0 avg 0.0 max 0.0 stddev 0.0 (0 samples)
Reply time [ms]: response 0.4 transfer 0.1
Reply size [B]: header 124.0 content 43.0 footer 0.0 (total 167.0)
Reply status: 1xx=0 2xx=1500 3xx=0 4xx=0 5xx=0

CPU time [s]: user 0.34 system 0.94 (user 26.7% system 73.2% total 99.9%)
Net I/O: 264.5 KB/s (2.2*10^6 bps)

Errors: total 0 client-timo 0 socket-timo 0 connrefused 0 connreset 0
Errors: fd-unavail 0 addrunavail 0 ftab-full 0 other 0


I.e., I can't even figure out what the end-to-end response time is.
I presume it is *not* the connection time.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMmz1OeOzq2AxjWknLxzGLOY1rJDHcjwV1dMFokc3S5%2BtxympA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Go will shine on huge web projects, but how about simple ones?

2019-06-08 Thread Tong Sun
Agree that it was not an apples to apples comparison. So please check
out my 2nd blog:

https://dev.to/suntong/simple-web-server-in-perl-and-go-revisit-5d82

> thanks to Axel Wagner, who replaced the net/http.Server layer with direct 
> translation of Perl code, the code is now reading and writing directly to a 
> socket, just as what the Perl code is doing.

@Budi, links to my Go code are available in both of my posts.


On Fri, Jun 7, 2019 at 8:08 PM Ivan Bertona wrote:
>
> Looking a the two code samples I wouldn't say this is an apples to apples 
> comparison... The Perl script seems to be a simple single-threaded loop that 
> understands a tiny subset of HTTP vs. a fully-fledged (and secure) web server 
> from the Go standard library. I would definitely not run that Perl script in 
> production, even if it was for a simple project. My bet is that if you 
> actually port the Perl script to a Go program that does more or less the same 
> thing you'll see more or less the same performance (because the example is 
> fundamentally I/O-bound).
>
> Best,
> Ivan
>
> On Friday, June 7, 2019 at 9:36:49 AM UTC-4, Tong Sun wrote:
>>
>> I had always believed that the web projects build with Go should be much 
>> faster than Perl, since Go is a compiled language.
>>
>> However that belief was crushed brutally last night, when I did a comparison 
>> -- the Go implementation is 8 times worse than the Perl! -- the mean 
>> response time jumped from 6ms to 48ms.
>>
>> I know this is the simplest possible web server, but still, when it comes to 
>> simple web servers like this, I have to say that Perl performs much better 
>> than Go.
>>
>> I don't think there is much I can twist on the Go side, since it can't be 
>> more simpler than that. However, I also believe it won't hurt to ask and 
>> confirm. So,
>>
>> Have I missed anything? Is it possible for me to make my Go implementation 
>> anywhere near the Perl's performance?
>>
>> Thanks
>>
>>
> --
> You received this message because you are subscribed to a topic in the Google 
> Groups "golang-nuts" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/golang-nuts/iH2Ck_hpCpI/unsubscribe.
> To unsubscribe from this group and all its topics, 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/12e7666a-385f-47ef-b061-9738802e7a88%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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/CAMmz1OcOMggESp%3D9GaPSLQUo89bmnGDtm7-KM1i3i%3DNiJQN5TA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Go will shine on huge web projects, but how about simple ones?

2019-06-07 Thread Tong Sun
I had always believed that the web projects build with Go should be much 
faster than Perl, since Go is a compiled language. 

However that belief was crushed brutally last night, when I did a 
comparison -- the Go implementation is *8 times worse 
* 
than the *Perl*! -- the *mean *response time jumped from 6ms to 48ms. 

I know this is the simplest possible web server, but still, when it comes 
to simple web servers like this, I have to say that Perl performs much 
better than Go.

I don't think there is much I can twist on the Go side, since it can't be 
more simpler than that. However, I also believe it won't hurt to ask and 
confirm. So,

Have I missed anything? Is it possible for me to make my Go implementation 
anywhere near the Perl's performance?

Thanks


-- 
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/c78e25f4-d2f8-462b-b227-f3ec6edae9fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Avoid global variables in Http handlers

2019-06-04 Thread Tong Sun
Oh, yeah, that works. Thanks Aldrin.

The reason that I'm asking is that the "solution" that I found on the web 
isn't working for me:

Here is a BETTER example (not using global variables):


type specificHandler struct {
Thing string}

func (h *specificHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Write(h.Thing)}

func main() {
http.Handle("/something", {Thing: "Hello world!"})
http.ListenAndServe(":8080", nil)}



On Monday, June 3, 2019 at 11:55:46 PM UTC-4, Aldrin Leal wrote:
>
> wrapping into a typedef?
>
> typedef MyHandler struct {
>   GlobalThing string
> }
>
> func (h *MyHandler) handle(w http.ResponseWriter, r *http.Request) {
> }
>
> func main() {
>   h := MyHandler{}
>
>   http.HandleFunc("/", MyHandler.handle)
> }
>
> --
> -- Aldrin Leal, > / 
> https://ingenieux.io/about/
>
>
> On Mon, Jun 3, 2019 at 10:48 PM Tong Sun > 
> wrote:
>
>>
>> Here is a BAD example (using global variables):
>>
>>
>> var globalThing string
>>
>> func specificHandler(w http.ResponseWriter, r *http.Request) {
>> w.Write(globalConfigThing)}
>>
>> func main() {
>> globalThing = "Hello world!"
>> http.HandleFunc("/something", specificHandler)
>> http.ListenAndServe(":8080", nil)}
>>
>>
>> How to avoid using global variables? 
>>
>> thx
>>
>>
>>
>> -- 
>> 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 golan...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/1bc9f505-9638-49e2-b873-6f4d7b88dfbc%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/1bc9f505-9638-49e2-b873-6f4d7b88dfbc%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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/90caaf41-cec3-4ba8-9d07-bf9080923cfa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Avoid global variables in Http handlers

2019-06-03 Thread Tong Sun


Here is a BAD example (using global variables):


var globalThing string

func specificHandler(w http.ResponseWriter, r *http.Request) {
w.Write(globalConfigThing)}

func main() {
globalThing = "Hello world!"
http.HandleFunc("/something", specificHandler)
http.ListenAndServe(":8080", nil)}


How to avoid using global variables? 

thx



-- 
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/1bc9f505-9638-49e2-b873-6f4d7b88dfbc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] go version go1.12 and cannot find module providing package

2019-05-30 Thread Tong Sun
Hi, 

For this line,

https://github.com/go-jsonfile/jsonfiddle/blob/f44996d66c751dac409d15e5f132a65ece42da59/cmd_x2j.go#L17

I'm getting

build github.com/go-jsonfile/jsonfiddle: cannot load 
github.com/mkideal/cli/clis: cannot find module providing package 
github.com/mkideal/cli/clis

when building under go version go1.12. 
And things were fine before go1.12. 

Where the problem is? 
How to fix it? -- I've tried.

go get -v -u github.com/mkideal/cli

and

go get -v -u github.com/mkideal/cli/clis

but neither works. 

Is it because how the package is defined? But that's not much different 
from:
https://github.com/mkideal/cli/blob/41df2d00b0edfa4614da67cf68f41df9d4e55539/ext/decoders.go#L1
but how come that package is OK? 

Thx

-- 
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/8ed57e68-4b13-4869-a9b8-efe69e49dda7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Http header and CR LF

2019-05-29 Thread Tong Sun
A question related to Go as "\n" in Go does not mean CR LF -- 

Is http header requires CR LF as line end? 
Perl can handle "\n" automatically for CR LF, but I saw a Perl program ends 
each http header specifically with CR LF. 

Shall I care about doing the same thing for my Go http handling? 


-- 
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/e3ea401d-d40a-4535-8d8c-bec9c539a1c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Http Handler to produce static content

2019-05-19 Thread Tong Sun
Thanks a lot Tamás! That's very clear & helpful!

On Sun, May 19, 2019 at 10:54 AM Tamás Gulácsi  wrote:
>
> ETag and Last-Modified are just to allow the browser to decide with a HEAD 
> request, whether GET the whole resource.

-- 
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/CAMmz1OeKxOVbP9%3DTZb1z%2Bxg%2BgqSpBY8u%3D5ueHp0PjXV9h5Kf%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Http Handler to produce static content

2019-05-19 Thread Tong Sun
Sorry I don't quite understand -- my go application IS my webserver.

Are you saying Go net/http is not capable of doing what I'm asking?

On Sun, May 19, 2019 at 9:59 AM satyendra singh
 wrote:
>
> Hi Tong,
> You can use a webserver between browser and your go application which will 
> take care of header modification for browser caching.
>
> Thanks and regards,
> Satyendra
>
> On Sun, 19 May, 2019, 7:26 PM Tong Sun,  wrote:
>>
>> Hi,
>>
>> How to have http.Handle / http.HandleFunc to produce static content that 
>> browser will use their caches without downloading every time?
>>
>> For a simplest http.HandleFunc, like the following,
>>
>> func sayHello(w http.ResponseWriter, r *http.Request) {
>>message := "Hello "
>>
>>w.Write([]byte(message))
>> }
>>
>>
>>
>> Thet HTTP Header it produce is:
>>
>> HTTP/1.1 200 OK
>> Date: Sun, 19 May 2019 13:46:32 GMT
>> Content-Length: 6
>> Content-Type: text/plain; charset=utf-8
>>
>>
>> I.e., the "Date:" part is changing all the time, even if I've added a 
>> "last-modified" Header field.
>>
>> What's the solution? Thx

-- 
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/CAMmz1OeBW5rp4RcfYtC%3Dk%3DpeX%3DdizF5G9Gv0Y1dgm5%2BG3%3DZBYA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Http Handler to produce static content

2019-05-19 Thread Tong Sun
Hi, 

How to have http.Handle / http.HandleFunc to produce static content that 
browser will use their caches without downloading every time? 

For a simplest http.HandleFunc, like the following, 

func sayHello(w http.ResponseWriter, r *http.Request) {
   message := "Hello "

   w.Write([]byte(message))
}



Thet HTTP Header it produce is:

HTTP/1.1 200 OK
Date: Sun, 19 May 2019 13:46:32 GMT
Content-Length: 6
Content-Type: text/plain; charset=utf-8


I.e., the "Date:" part is changing all the time, even if I've added a 
"last-modified" Header field. 

What's the solution? Thx



-- 
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/f2adf5e4-5486-4bbe-9860-a6639a1142e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go linker efficiency

2019-05-18 Thread Tong Sun


On Saturday, May 18, 2019 at 1:52:43 AM UTC-4, Ian Lance Taylor wrote:
>
> On Fri, May 17, 2019 at 9:12 PM Tong Sun > 
> wrote: 
> > 
> > How efficient Go linker is in detecting unused things (e.g., functions) 
> in a package during build and remove them from the compiled binary? 
> > 
> > To extremely simplify the case, say 
> > 
> > - I have a package that contains 10 individual functions, and each of 
> them will compile to 10K in binary size. 
> > - Then a program calls one single function from such package. 
> > 
> > Will the compiled binary executable be 10K more in size, because of 
> calling that one single function, or 100K more? 
> > 
> > I.e., will using a tiny portion of a big package cost me the whole big 
> package in compiled binary size, or only the tiny portion that I used? 
>
> The linker will discard all unused functions and variables, but will 
> not discard unused methods. 
>


Thanks, Ian 

So in other words, if a package A that I'm using is importing 10 
other packages, and as long as any of the packages' methods are used 
within package A's methods, all related methods from those 10 other 
packages will be compiled & included in the binary executable, right? 

E.g., if I'm using a package just for CLI processing, however if the 
package is doing some funky processing in its methods that use packages of 
net, net/http, net/url, all related methods from net, net/http, net/url 
will end up within my binary executable, right?

thx


-- 
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/b42b7e71-ad55-496f-9c86-35f479b649e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Go linker efficiency

2019-05-17 Thread Tong Sun
Hi, 

How efficient Go linker is in detecting unused things (e.g., functions) in 
a package during build and remove them from the compiled binary? 

To extremely simplify the case, say 

- I have a package that contains 10 individual functions, and each of them 
will compile to 10K in binary size. 
- Then a program calls one single function from such package. 

Will the compiled binary executable be 10K more in size, because of calling 
that one single function, or 100K more? 

I.e., will using a tiny portion of a big package cost me the whole big 
package in compiled binary size, or only the tiny portion that I used?

thx

-- 
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/cb880ac4-394c-443b-941e-201fc282ddc8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Need help to make autocert working

2019-05-07 Thread Tong Sun


On Tuesday, May 7, 2019 at 9:42:52 PM UTC-4, Kurtis Rader wrote:
>
> On Tue, May 7, 2019 at 6:07 PM Tong Sun > 
> wrote:
>
>> I've been trying to get an TLS server up and running for the past several 
>> days without success. I've used the following guides as reference:
>>
>
> FWIW, I recommend the Caddy HTTPS web server rather than rolling your own. 
> It took me just a few minutes to setup with a cert it automatically 
> acquired from LetsEncrypt. It's written in Go. And it already has a rich 
> set of plugins such as ipfilter <https://github.com/pyed/ipfilter> that I 
> contributed an enhancement to. See https://caddyserver.com/
>

Thanks Kurtis, I'll for sure using it for some serious. 

For now, I need the program as minimalist as possible, because I'm trying 
to rewrite this small Perl code as Go, 
https://github.com/suntong/dbab/blob/master/src/bin/dbab-svr#L94
whose only purpose is to severve an 1x1 pixel. 


-- 
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/6d00f0dd-2fa2-4a7d-9a39-68645c2029af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Need help to make autocert working

2019-05-07 Thread Tong Sun
Hi, 

I've been trying to get an TLS server up and running for the past several 
days without success. I've used the following guides as reference:

https://goenning.net/2017/11/08/free-and-automated-ssl-certificates-with-go/ 
https://blog.kowalczyk.info/article/Jl3G/https-for-free-in-go-with-little-help-of-lets-encrypt.html

and many more. 
But for all of them I'm getting


This site can’t be reached
site took too long to respond.


The latest code that I tried is 
https://gist.github.com/samthor/5ff8cfac1f80b03dfe5a9be62b29d7f2

whose console log was:

2019/05/07 20:27:16 Serving http/https for domains: [my.domain.com]
2019/05/07 20:28:05 http: TLS handshake error from 99.xx.xx.221:43662: EOF

The previous errors I got from console log were:

2019/05/07 11:11:11 http: TLS handshake error from 99.xx.xx.221:40820: 
context deadline exceeded
2019/05/07 11:11:11 http: TLS handshake error from 99.xx.xx.221:40826: 
acme/autocert: missing certificate
. . . 


The console log looked very strange to me -- 

- I have a real site with real DNS name. 
- I ssh into the box as me, and start the program as:

 sudo ./autocert-server my.domain.com

However, that 99.xx.xx.221 from all logs is my own home IP address (with a 
different domain name). 
How come the autocert TLS handshake trying to connect my home IP address, 
instead of the remote server that I run the web site from and provide the 
real DNS name with? 

thx

-- 
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/9ff1d193-93fb-45a1-8e1e-1688cf5fec17%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: The go way to compare values against an enum

2019-04-16 Thread Tong Sun
Roger and Jan have given you good answers, but if you want to make use of 
an existing *small *package, check out 

https://github.com/suntong/enum



On Monday, April 15, 2019 at 4:52:52 AM UTC-4, Sankar wrote:
>
> Hi,
>
> I have the following Go type.
>
> ```
> type weekday string
>
> const (
>   Monday weekday = "Monday"
>   Tuesday = "Tuesday"
>   .
>   .
>   .
> )
> ```
>
> Now I have a function that receives a string parameter and I want to 
> evaluate if it s a valid weekday or not. Say:
>
> ```
> func handler(w http.ResponseWriter, r *http.Request) {
>
> // Parse req.body and get a day string
>
> day := "Tuesday" // Valid day
> day := "tuesday" // Invalid day
> day := "123819283" // Invalid day
>
> }
> ```
>
> I want to evaluate if the string variable `day` is one of the valid 
> permitted values for the [Ww]eekday custom type. What is the recommended / 
> right go way of doing this ?
>
> Thanks.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: [ANN] Lightweight package for exposing application metrics in Prometheus format

2019-04-16 Thread Tong Sun


On Tuesday, April 16, 2019 at 12:13:17 PM UTC-4, Aliaksandr Valialkin wrote:
>
> Hi all,
>
> I'm glad to announce a lightweight package for exposing application 
> metrics in Prometheus format - https://github.com/VictoriaMetrics/metrics
>  .
>
> The package provides the following most frequently used metric types:
> - Counter
> - Gauge
> - Summary
>
> The metrics package has the following features:
> - it provides clear API 
> , which is much 
> easier to use comparing to the official Prometheus package for exporting 
> application metrics - github.com/prometheus/client_golang 
>  .
> - it has much smaller dependencies comparing to 
> github.com/prometheus/client_golang 
>  , so it compiles 
> quicker to a smaller binary code.
> - it is optimized for speed.
>
> The github.com/VictoriaMetrics/metrics has been extracted from 
> VictoriaMetrics 
> 
> .
>

well done,  thx!

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Easy to use (getopt based) flags package

2019-04-10 Thread Tong Sun
take a look at

https://github.com/mkideal/cli

It's declarative, generate help-text/usage for you, and support sub 
commands, and even sub sub commands. 

just + my 2c.


On Wednesday, April 10, 2019 at 6:59:37 AM UTC-4, mhh...@gmail.com wrote:
>
> looks lovely, how do you manage sub commands ?
>
> On Wednesday, April 10, 2019 at 2:24:21 AM UTC+2, Paul Borman wrote:
>>
>> I have never been quite happy with the flags packages available for Go, 
>> including the standard flags package as well as my own getopt packages (v1 
>> and v2).  They are just too cumbersome to use.  I finally have come up with 
>> a solution that I like.  github.com/pborman/options 
>> 
>>
>> The command line options are declared as a simple structure with struct 
>> tags, for example:
>>
>> // Declare the command line flags.  The help information does not need to 
>> line up,
>> // I just think it looks prettier this way.
>> var opts = struct {
>> Helpoptions.Help  `getopt:"--help   display help"`
>> Namestring`getopt:"--name=NAME  name of the widget"`
>> Count   int   `getopt:"--count -c=COUNT number of widgets"`
>> Verbose bool  `getopt:"-v   be verbose"`
>> Timeout time.Duration `getopt:"--timeoutduration of run"`
>> }{
>> Name: “gopher”,
>> }
>>
>> func main() {
>> // Assign args to the positional parameters.
>> args := options.RegisterAndParse()
>>
>> fmt.Printf(“Name is: %s\n”, opts.Name)
>> …
>> }
>>
>> The command usage displayed by passing —help to the above program will 
>> look something like:
>>
>> Usage: prog [-v] [-c COUNT] [--help] [--name NAME] [--timeout value] 
>> [parameters ...]
>>  -c, --count=COUNT  number of widgets
>>  --help display help
>>  --name=NAMEname of the widget [gopher]
>>  --timeout=value
>> duration of run
>>  -v be verbose
>>
>> The package is built on top of the github.com/pborman/getopt/v2 
>>  package and as such 
>> they can be used together.  The options package also supports reading 
>> command line arguments from a file by using the options.Flags type.
>>
>> I hope that some of you might find this helpful in writing command line 
>> programs.
>>
>> -Paul
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] go build not working for windows - got This version is not compatible with the version of Windows you're running.

2019-03-18 Thread Tong Sun
Hi, 

Shooting into dark to see if somebody has bumped into such problem before 
-- when I am building Go for a specific project, I'll get that "This 
version  is not compatible with the version of Windows you're running" 
error. 

Note, 

- I'll get the error *only *for that *specific *project, 
namely https://github.com/go-easygen/easygen. All other projects I built 
are fine so far. 
- The included packages from easygen are, according to `go build`:

$ GOOS=windows GOARCH=amd64 go build -v -a -o $prj.exe
errors
internal/race
runtime/internal/atomic
runtime/internal/sys
sync/atomic
internal/cpu
runtime
math
internal/syscall/windows/sysdll
unicode/utf16
unicode/utf8
internal/testlog
strconv
unicode
encoding
sync
io
syscall
reflect
internal/syscall/windows
internal/syscall/windows/registry
time
bytes
internal/poll
encoding/binary
encoding/base64
os
sort
strings
fmt
regexp/syntax
path/filepath
regexp
io/ioutil
net/url
gopkg.in/yaml.v2
text/template/parse
text/template
_/path/to/go-easygen/easygen


- here is what happened when run under Windows:

C:\>easygen
This version of D:\Tools\easygen.exe is not compatible with the version of 
Windows you're running. Check your computer's system information and then 
contact the software publisher.


My go is:

$ go version 
go version go1.10.1 linux/amd64

$ apt-cache policy golang-1.10-go
golang-1.10-go:
  Installed: 1.10.1-1ubuntu2
  Candidate: 1.10.4-2ubuntu1~18.04.1
  Version table:
 1.10.4-2ubuntu1~18.04.1 500

500 http://ca.archive.ubuntu.com/ubuntu bionic-updates/main amd64 
Packages

 

Any help appreciated. 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Go playground to support none-standard modules

2019-03-09 Thread Tong Sun
I know Go playground does not support none-standard modules. 
Is there any online site that does support none-standard modules?

For online code-running sites for any other languages, they all 
support none-standard modules. 
Go is the only one that I know which doesn't, while godoc is already 
supporting every possible Go package on earth. 

Hope it'll be changed someday. 

cheers

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] [Ann] create full github release from command line, not just a tag

2019-01-07 Thread Tong Sun
No they're not, you're in good hands with cross-compiled assets etc.
The wireframe project is extremely light-weighted and much easier to get
started with.

On Sun, Jan 6, 2019 at 11:58 PM Justin Israel 
wrote:

> I've been using goreleaser <https://goreleaser.com/> so far, to publish
> github releases with cross-compiled assets. I am not familiar with the
> wireframe project though. Do they share some overlap?
>
> On Mon, Jan 7, 2019 at 5:50 PM Tong Sun  wrote:
>
>> IIRC, github used to create full releases each time you push a git
>> tag, but now it only creates tags, not releases. After pushing a git tag,
>> people need to go to GitHub UI, find created tag, press "Edit tag", change
>> nothing and press "Publish release", then they'll get full release and
>> event.
>>
>> But I much prefer to be able to create full Release  with title,
>> description, or assets from the command line.
>> So I was wondering if there is any way to "Publish release" from a
>> command line.
>> and it turns out that now creating releases are via API:
>> https://developer.github.com/v3/repos/releases/#create-a-release
>>
>>
>> So I added the feature to easygen/wireframe, to "Publish release" from
>> command line. The details can be found at
>>
>> https://github.com/go-easygen/wireframe#github-create-release---create-release-in-github
>>
>>
>> --
>> 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.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] [Ann] create full github release from command line, not just a tag

2019-01-06 Thread Tong Sun
IIRC, github used to create full releases each time you push a git tag, but 
now it only creates tags, not releases. After pushing a git tag, people 
need to go to GitHub UI, find created tag, press "Edit tag", change nothing 
and press "Publish release", then they'll get full release and event. 

But I much prefer to be able to create full Release  with title, 
description, or assets from the command line. 
So I was wondering if there is any way to "Publish release" from a command 
line. 
and it turns out that now creating releases are via API:
https://developer.github.com/v3/repos/releases/#create-a-release


So I added the feature to easygen/wireframe, to "Publish release" from 
command line. The details can be found at
https://github.com/go-easygen/wireframe#github-create-release---create-release-in-github


-- 
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] GoAWK: an AWK interpreter written in Go

2018-11-24 Thread Tong Sun
On Sat, Nov 24, 2018 at 10:11 AM Ben Hoyt wrote:

For what it's worth, I found that tool quite interesting and relevant.
> Tong, I think you're overreacting a bit here.
>

 Oh, I'm sorry, *everyone*.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: go language sensitive editor?

2018-11-24 Thread Tong Sun
On Fri, Nov 23, 2018 at 11:40 AM Serge Voilokov wrote:

>
> No, no plans to PR for a while since I implemented the features directly
> in the source tree.
> I need to think how to wrap them as plugins for dynamic download.
>

What you believe can benefit yourself can surely benefit the Go community
as a whole.
I do hope you'll find your way to contribute your efforts back to the Go
community. thx.

At very least, since micro is programmed in Go, having Go features directly
in the source tree might not be an unacceptable way, :-)

-- 
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] GoAWK: an AWK interpreter written in Go

2018-11-24 Thread Tong Sun
On Sat, Nov 24, 2018 at 6:44 AM Denis Cheremisov wrote:

> >  - also enable normal go program to use awk scripts
>
> probably this  is better tool for the
> case
>

- please don't just post a link, but include descriptions.
- please justify your claim "better" - a specific log file parser is better
than general-purpose awk scripts? In what way?
- please don't hijack a thread in promoting your own tool, especially when
it is highly irreverent.

Thank you for your cooperation

-- 
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] GoAWK: an AWK interpreter written in Go

2018-11-23 Thread Tong Sun


On Saturday, November 17, 2018 at 12:44:57 PM UTC-5, Ben Hoyt wrote:
>
>
> https://benhoyt.com/writings/goawk/ 
> 
>
> It's pretty much a toy project, not being used for anything real, but it 
> seems to be in a good shape. Feedback welcome!
>

Hope there are future plans to extend it so that, 

- people can define user function in go and use it in goawk 

 handling, 
as kty... has pointed out. 
- also enable normal go program to use awk scripts

thx

-- 
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] Simple Go http daemon under systemd

2018-11-23 Thread Tong Sun
On Fri, Nov 23, 2018 at 3:03 PM Diego Medina wrote:

> that endpoint returns no html just because I don't need it, but the status
> 200 is there to tell me the app is running
>
> a go deamon is just a go binary, nothing special
>
> systemd works fine with any go binary that serves http
>

Wonderful. That's exactly what I need. Thx 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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Simple Go http daemon under systemd

2018-11-23 Thread Tong Sun
[resending, sorry sam]

On Fri, Nov 23, 2018 at 10:50 AM Sam Whited wrote:

> On Thu, Nov 22, 2018, at 21:14, Tong Sun wrote:
> > and it needs to be working under systemd.
> > …
> > but there is no mentioning of how it can work under systemd, which could
> > be
> > troublesome,
> > like the question I found at why systemd cannot start golang web app
> > <
> https://stackoverflow.com/questions/37297714/why-systemd-cannot-start-golang-web-app
> >
>
> I'm not really sure what you're asking, Go binaries aren't doing anything
> special and systemd can start them just like any other program. Are you
> looking for an example service/socket file that lets you bind to port 443,
> or wondering what type of service to use? Or are you getting some other
> kind of error?
>

Both Go http daemon and systemd, and new to me, and I was looking for an
example that they work well together, and I found above.

No, I'm not looking for an service/socket example, just normal Go http
server started from systemd, and the only thing I found them both mentioned
is in above stackoverflow question
<https://stackoverflow.com/questions/37297714/why-systemd-cannot-start-golang-web-app>
.

Hence I'm asking for a simplest Go http daemon that works under systemd.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: GoAWK: an AWK interpreter written in Go

2018-11-22 Thread Tong Sun


On Tuesday, August 28, 2018 at 9:06:22 AM UTC-4, Ben Hoyt wrote:
>
> Once you have some proper benchmarks, it might be fun to compare GoAWK's 
>> performance to that of my awk package .
>>
>
> Nice -- will do!
>
 
Please post back when you've done that. 

I'm interested to know. Thx. 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: go language sensitive editor?

2018-11-22 Thread Tong Sun
Nice added features Serge. 

Any plan to PR them back, or you'd rather keep your fork to your self? Thx. 


On Wednesday, November 21, 2018 at 4:57:05 PM UTC-5, Serge Voilokov wrote:
>
> I am using micro editor: https://github.com/zyedidia/micro . It is 
> terminal-based, supports mouse, uses ctrl+zxcv and shift+arrows for text 
> manipulation, has a multi cursor feature, syntax highlighting.
> Written in golang. Easy to configure and change.
> I am using my fork (https://github.com/serge-v/micro) with added features 
> for golang development: go to decls, go imports, go install, go complete, 
> etc.
>
> On Tuesday, November 20, 2018 at 3:52:11 PM UTC-5, Pat Farrell wrote:
>>
>> I know, this is both a FAQ and an unanswerable question. I'm an old 
>> programmer who has used nearly every editor known to man. I am not a fan of 
>> whole-universe IDEs, but can use them. I also speak vi/vim pretty fluently.
>>
>> What editors do folks use for go? I'd like something that can complete 
>> function names, understand imports, and give some assistance.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Simple Go http daemon under systemd

2018-11-22 Thread Tong Sun
Hi, 

I want to write a simple Go http daemon that return a static string 
regardless what the request is, 
like this 
one: https://github.com/suntong/dbab/blob/master/src/bin/dbab-svr#L20

and it needs to be working under systemd. 

*What is the best example that I can start with?* (They both, Go http 
daemon and systemd, and new to me)

I found 

enricofoltran /main.go 


A simple golang web server with basic logging, tracing, health check, 
graceful shutdown and zero dependencies


but it seems not supporting https requests,

I also found 

tabalt /gracehttp 


a simple and graceful HTTP server for Golang


which seems quite complete, it has nice single-handling and https support. 
but there is no mentioning of how it can work under systemd, which could be 
troublesome, 
like the question I found at why systemd cannot start golang web app 


Any help appreciated. Thx. 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Keep Vendor folder on library Repository is Bad or Good practice.

2018-08-13 Thread Tong Sun
I have no idea what's going on there or the history, but I see
https://github.com/jteeuwen/go-bindata is still there, despite that "this
repository is not maintained".

On Thu, Aug 9, 2018 at 8:58 AM peterGo  wrote:

> Tong Sun
>
> "I've never seen [the Author delete the library]  happen before."
>
> It happened recently. Take a look at jteeuwen/go-bindata: Hard fork of
> jteeuwen/go-bindata because it disappeared,
>
> Peter
>
> On Wednesday, August 8, 2018 at 10:01:32 AM UTC-4, Tong Sun wrote:
>>
>> I've never seen that happen before, but in case it does, only new
>> environments will fail, i.e., those has been building fine will still be
>> building fine. I.e. it's quite easy to correct.
>>
>> So I personally think that it is really a high price to pay for something
>> that may *never* happen.
>> Of course, not everyone agree with me, as I've seen someone even worries
>> that go yaml (gopkg.in/yaml.v2) will go away someday, and insists
>> vendering it.
>>
>>
>>
>> On Wednesday, August 1, 2018 at 9:50:13 AM UTC-4, nafis wrote:
>>>
>>> How about the Author delete the library.
>>>
>>> On Tuesday, July 31, 2018 at 5:49:36 AM UTC+6, Eric Johnson wrote:
>>>>
>>>> Long term, I suspect you're better off without the vendoring.
>>>>
>>>> Specifically, I suggest looking into automating your libraries tests
>>>> with the earliest possible versions of supported dependencies, and the
>>>> latest versions of dependencies.
>>>>
>>>> With a tool like vgo, it should be possible to have two versions of
>>>> your lock file that your build / test cycle can switch between. If a
>>>> project adds backwards compatible changes, they you can test across major
>>>> versions as well.
>>>>
>>>> Eric
>>>>
>>>> On Saturday, July 28, 2018 at 11:43:04 AM UTC-7, nafis wrote:
>>>>>
>>>>> Suppose I'm making a library and it does reference some other library
>>>>> not part of the standard library. I want to vendor those so that my 
>>>>> library
>>>>> doesn't fail if the other 3rd party developer deletes their library or
>>>>> major changes of their library(I know this sound like stupid design). And 
>>>>> I
>>>>> want to push the vendor folder on my library repo. My question: Is
>>>>> this the bad idea keep a vendor folder on the library repo.
>>>>>
>>>>> Thank you for your time.
>>>>>
>>>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/yASFt3PY_yg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Keep Vendor folder on library Repository is Bad or Good practice.

2018-08-08 Thread Tong Sun
IMHO, the npm node packaging is just a mess -- I have several similar 
projects, and each has to pull in a HUGE pile of almost-identical 
dependencies, and not able to reuse between them at all. Whatever happening 
over there will not astonish me at all, including the infamous 
npm_left_pad_chaos 

 problem. 

Go packaging is far super than npm -- chaos at npm does not imply Go will 
suffer the same. 

On Wednesday, August 8, 2018 at 10:14:31 AM UTC-4, Manlio Perillo wrote:
>
> https://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/ 
> 
>
> Manlio
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Keep Vendor folder on library Repository is Bad or Good practice.

2018-08-08 Thread Tong Sun
I've never seen that happen before, but in case it does, only new 
environments will fail, i.e., those has been building fine will still be 
building fine. I.e. it's quite easy to correct. 

So I personally think that it is really a high price to pay for something 
that may *never* happen. 
Of course, not everyone agree with me, as I've seen someone even worries 
that go yaml (gopkg.in/yaml.v2) will go away someday, and insists vendering 
it. 



On Wednesday, August 1, 2018 at 9:50:13 AM UTC-4, nafis wrote:
>
> How about the Author delete the library.
>
> On Tuesday, July 31, 2018 at 5:49:36 AM UTC+6, Eric Johnson wrote:
>>
>> Long term, I suspect you're better off without the vendoring.
>>
>> Specifically, I suggest looking into automating your libraries tests with 
>> the earliest possible versions of supported dependencies, and the latest 
>> versions of dependencies.
>>
>> With a tool like vgo, it should be possible to have two versions of your 
>> lock file that your build / test cycle can switch between. If a project 
>> adds backwards compatible changes, they you can test across major versions 
>> as well.
>>
>> Eric
>>
>> On Saturday, July 28, 2018 at 11:43:04 AM UTC-7, nafis wrote:
>>>
>>> Suppose I'm making a library and it does reference some other library 
>>> not part of the standard library. I want to vendor those so that my library 
>>> doesn't fail if the other 3rd party developer deletes their library or 
>>> major changes of their library(I know this sound like stupid design). And I 
>>> want to push the vendor folder on my library repo. My question: Is this 
>>> the bad idea keep a vendor folder on the library repo.
>>>
>>> Thank you for your time.
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


  1   2   3   4   >