[go-nuts] Re: trouble parsing XML with embedded structs

2020-06-06 Thread Ain
On Thursday, June 4, 2020 at 9:06:50 PM UTC+3, Lars R. Damerow wrote:
>
> Hello all, 
>
> I need to parse XML messages from a source I don't control. Each one has 
> an envelope node that shows its source, and the first node in that envelope 
> encodes the message type. I'm trying to compose structs to make it easier 
> to do the parsing, and I put a stripped-down example for just one message 
> type on the playground here: 
>
> https://play.golang.org/p/tszPHRM-mMO 
>
> What's puzzling me here is that, after unmarshaling, 
> `v.Envelope.XMLName.Local` is empty. I'd expect it to contain "proto-alpha" 
> from the example XML in the source; it does pick up the version attribute 
> that's set on the envelope node, just not the `xml.Name` value. 
>
> Can anyone share some clues about what I'm doing wrong here? 
>

You have a extra layer there in the structs, try this

type Envelope struct {
XMLName xml.Name
Version string `xml:"version,attr"`
Body GreetingBody
}

type GreetingBody struct {
XMLName xml.Name `xml:"greeting"`
Str string   `xml:"str"`
}


func main() {
var input = `

  
 hello
  

`
v := Envelope{}
if err := xml.Unmarshal([]byte(input), ); err != nil {
log.Panic(err)
}

fmt.Printf("%+v\n", v)
} 

HTH
ain

-- 
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/80e1fd8d-f684-46e6-810e-ba7b02d04b4do%40googlegroups.com.


[go-nuts] Re: godoc (golang.org/x/tools/cmd/godoc) has become module-aware

2019-11-08 Thread Ain


On Friday, November 8, 2019 at 8:52:07 PM UTC+2, Dmitri Shuralyov wrote:
>
> Hello gophers,
>
> godoc <https://golang.org/x/tools/cmd/godoc>, the local web server that 
> displays documentation for Go packages (not to be confused with 
> https://godoc.org, the website), has been updated with support for Go 
> modules. (This was issue 33655 <https://golang.org/issue/33655>.)
>

Great news, thank you! 

Ain

-- 
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/ce9e20ff-9388-4e7e-bbcd-b2a088c8d5e8%40googlegroups.com.


[go-nuts] About godoc and private doc server

2019-05-30 Thread Ain
Hi

It seems that godoc doesn't work with modules, in the sense that it doesn't 
find / show documentation of the modules outside GOPATH...?

And about doc server... say I want to have private godoc server, mainly to 
serve doc of some private libs (hosted on github, but private repos) but 
wouldn't mind if it also contains stdlib doc and popular "public libs" - 
what options do I have? I can think of two:

1) something godoc based - install the libs into GOPATH, launch godoc and 
expose it... probably have to create custom template too;
2) use godoc.org, available at github golang/gddo repo.

Any other options?
Any tips how to set it up (ie what needs to be done to get godoc.org up and 
able to access private repos)?


TIA
ain

-- 
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/e5d53b6a-5212-41d9-be10-2c6463aeef7d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: emersion/go-imap - How to retrieve and list unseen messages

2018-02-27 Thread Ain

teisipäev, 27. veebruar 2018 15:11.58 UTC+2 kirjutas Ivo Freitas:
>
> Hello
>
> I'm trying to use this implementation of IMAP protocol mas seems to be 
> impossible to retrieve unseen messages from the mailbox.
>

Cross-posted to SO:
https://stackoverflow.com/q/49009432/723693


ain

-- 
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: Email sent via command line is not delivered in Golang

2018-01-24 Thread Ain

Cross-posted to 
SO: 
https://stackoverflow.com/questions/48421688/email-sent-via-command-line-is-not-delivered-in-golang


ain


kolmapäev, 24. jaanuar 2018 13:49.05 UTC+2 kirjutas Amandeep Kaur:
>
>
>
>
> I am sending emails in one of my projects through command line. The 
> project back end is written in Golang. I am using following code to send 
> emails:
>
 

-- 
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: How to send multiple responses (file upload progress) to the client?

2018-01-05 Thread Ain
On Friday, January 5, 2018 at 10:51:09 PM UTC+2, Jason Lee wrote:
>
> I've set up a GoLang post request handler that uploads a file to Google 
> Cloud Storage.
>
> Now I'd like to figure out how I can send the upload progress info back to 
> the client before the whole thing finishes.
>

If the client is browser and uses XMLHttpRequest to POST the file then it 
can use XMLHttpRequest.upload.onprogress eventhandler to track the 
progress. No need to do anything on the server side for that to work.

 
HTH
ain

-- 
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: Embedded WebBroser

2017-12-29 Thread Ain
On Friday, December 29, 2017 at 8:58:33 PM UTC+2, Jason Petersson wrote:
>
> Hello is there a GitHub project or example of an application that can be 
> built for calling simple html and maybe java script?
>

https://github.com/zserge/webview

https://github.com/asticode/go-astilectron

 
HTH
ain

-- 
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 Generate Vs Go Build!

2017-12-17 Thread Ain


On Sunday, December 17, 2017 at 11:45:12 PM UTC+2, Compiler wrote:
>
> - https://en.wikipedia.org/wiki/Go_(programming_language)
> - go build, which builds Go binaries using only information in the source 
> files themselves, no separate makefiles
> - go test, for unit testing and microbenchmarks
> - go fmt, for formatting code
> - go get, for retrieving and installing remote packages
> - go vet, a static analyzer looking for potential errors in code
> - go run, a shortcut for building and executing code
> - godoc, for displaying documentation or serving it via HTTP
> - gorename, for renaming variables, functions, and so on in a type-safe 
> way
> - go generate, a standard way to invoke code generators
>
> Please explain me.
>

Have you seen https://golang.org/cmd/go/


HTH
ain

-- 
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: How to check if a request was cancelled

2017-11-08 Thread Ain

I noticed that OP has also posted this question to SO:
https://stackoverflow.com/questions/47179024/how-to-check-if-a-request-was-cancelled


ain


kolmapäev, 8. november 2017 14:02.13 UTC+2 kirjutas Glen Huang:
>
> I have this simple code in which I try to check if the request was 
> cancelled. But surprisingly, it prints false instead of true in go 1.9.
>
> I wonder what's the correct way to check that?
>
> package main
>
>
> import (
> "context"
> "log"
> "net/http"
> )
>
>
> func main() {
> r, _ := http.NewRequest("GET", "http://example.com;, nil)
> ctx := context.Background()
> ctx, cancel := context.WithCancel(ctx)
> r = r.WithContext(ctx)
> ch := make(chan bool)
> go func() {
> _, err := http.DefaultClient.Do(r)
> log.Println(err == context.Canceled)
> ch <- true
> }()
> cancel()
> <-ch
> }
>

-- 
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: XML parsing and memory usage

2017-11-01 Thread Ain
On Wednesday, November 1, 2017 at 6:36:25 PM UTC+2, Felipe da Veiga 
Leprevost wrote:
>
> Hey;
>
> I'm developing a pipeline that takes as input XML files with a reasonable 
> complex structure and size, the nested structure might have several layers 
> and these files can go from 900 MB to 3 GB in size. I can't change that 
> because it's not on my control how they are formed, I just need to read 
> them.
>
> Right now I have the pipeline working by mapping a nested group of structs 
> to the XML file, something like this:
>
> (code already works, this is just to server as an example on how I'm doing)
> ```
> xmlFile, e := os.Open(f)
> if e != nil {
> return e
> }
>
> defer xmlFile.Close()
>
> b, _ := ioutil.ReadAll(xmlFile)
>
> var xmlHead XmlHeadStruct
>
> reader := bytes.NewReader(b)
> decoder := xml.NewDecoder(reader)
> decoder.CharsetReader = charset.NewReader
>
> if e = decoder.Decode(); e != nil {
> return e
> }
> ```
>
> Now, everything works perfectly but with one exception, the memory usage! 
> A file with approximately 900 MB is consuming 4 GB RAM and one with 3.3 GB 
> can consume almost 14 GB RAM. Not cool!
>
> Do you guys have any suggestions on how to circumvent this ?
>

One option is to use "streaming mode", see ie
http://blog.davidsingleton.org/parsing-huge-xml-files-with-go/
 

HTH
ain

-- 
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: How to know if interface{} data is nil w/o reflecting?

2017-11-01 Thread Ain

On Wednesday, November 1, 2017 at 3:37:54 PM UTC+2, Ayan George wrote:
>
>
>
> On 11/01/2017 07:18 AM, oju...@gmail.com  wrote: 
> > Ayan, imagine I am part of a development team. In our program I have a 
> > pointer r: 
> > 
> > r *myType 
> > 
> > My variable r can be nil, because that is a valid situation. It is used 
> > in dozens of places, like this: 
> > 
> > if r != nil { 
> > r.doSomething() 
> > } 
> > 
> > That is a very usual idiom, no only in Go, but in many languages. Every 
> > programmer is acquainted to that. 
> > 
> > Then, years later, other programmer in my team decides to create an 
> > interface to better capture a new understanding of the problem at hand, 
> > changing the type of r to: 
> > 
> > r myInterface 
> > 
> > Subtly, the meaning of 
> > 
> > if r != nil { 
> > r.doSomething() 
> > } 
> > 
> > changes. Under the right circumstances our software starts to behave 
> > strangely. What? 
> > 
> > This problem is dangerous because it is so subtle. We will read our old 
> > code time and again to no avail, because everything seems fine and no 
> > one has changed that "if r != nil r.doSomething" in ages. 
> > 
>
> I think I understand what you're saying. The thing is: You changed the 
> type of r and I don't believe anyone ever promised that you can change 
> the type of a variable to an interface AND preserve its behavior. 
>
> Would you expect r to behave the same if you changed it from type string 
> to an int? 
>

Point is, in that case compiler would catch it for you and you wouldn't be 
able to compile until you fix all the parts of the code which now doesn't 
make sense. Not so in the case JuciÊ Andrade pointed out.


ain

-- 
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] Cross-platform HTML/CSS GUI library

2017-10-25 Thread Ain

On Wednesday, October 25, 2017 at 3:39:42 PM UTC+3, Serge Zaitsev wrote:
>
> Hey all,
>
> I made a tiny library that provides a cross-platform web UI for Go apps.
>
> https://github.com/zserge/webview
>

Looks intresting, thanks for making it available!
 
 

>  
>
Apart from the app architecture, I wonder what features do you think this 
> library lacks for your needs, or what could be done better.
> Any ideas, feedback or critique are welcome.
>

Of the top of my head:
 - callback when app is terminated (via the [x] button on titlebar);
 - ability to create native menu for the main wnd;
 - ability to set app icon.


ain

-- 
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: database/sql - prepared select statements only work on first invocation

2017-08-28 Thread Ain
On Monday, August 28, 2017 at 10:13:28 PM UTC+3, Uli Kunitz wrote:
>
> I can't replicate your issue. I have create following example, which works 
> perfectly for me on Linux, AMD64 and go 1.9:
>
> https://gist.github.com/ulikunitz/d5335e0667fb57b2d12c8ffa5404b031
>
> You  should create something comparable so that others can test your code.
>

Your code works for me too. But If I swich to firebird driver then the 
error is back... Might be driver specific issue after all... must test some 
more.
Thakns for taking time to test it.


ain

-- 
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: database/sql - prepared select statements only work on first invocation

2017-08-28 Thread Ain

On Monday, August 28, 2017 at 7:37:42 PM UTC+3, Tamás Gulácsi wrote:
>
> QueryRow closes the underlyin Stmt - see the docs.


Where in the doc this is mentioned?

https://godoc.org/database/sql#Stmt.QueryRow
<>
 
https://godoc.org/database/sql#Tx.QueryRow
<>

I also had a quick look at the code and didn't see the statement closed 
(but I have not digged really into code, just a quick look).


ain

-- 
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: database/sql - prepared select statements only work on first invocation

2017-08-28 Thread Ain

On Monday, August 28, 2017 at 5:07:30 PM UTC+3, Christian Joergensen wrote:
>
> On Monday, August 28, 2017 at 3:52:54 PM UTC+2, Ain wrote:
>>
>> Does anyone use prepared select statements sucessfully? With which 
>> DB/driver?
>> I'm sure that if my code is silly someone would have pointed it out so 
>> I'm wondering am I the only one trying to use prepared select statements...
>>
>
> Have you seen the last comment on:
> https://godoc.org/database/sql#Tx.Prepare
>

As I understand, this comment (To use an existing prepared statement on 
this transaction, see Tx.Stmt) doesn't apply to the code I posted, it would 
fall under the first part of the documentation.
 
 

> It looks like you're missing the call to:
> https://godoc.org/database/sql#Tx.Stmt
>

I don't think so. As I understand I would need to use Tx.Stmt 
<https://godoc.org/database/sql#Tx.Stmt> if I want to use an statement 
prepared outside of the current tx in the current tx. This is not the case 
with the code I posted - it prepares the statement in the tx and then tryes 
to use it twice.


ain

-- 
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: database/sql - prepared select statements only work on first invocation

2017-08-28 Thread Ain


On Monday, August 28, 2017 at 5:13:09 PM UTC+3, Uli Kunitz wrote:
>
> Where are you calling Exec on the statement?
>

I'm talking about SELECT statements.
https://godoc.org/database/sql#Tx.Exec
<>


ain

 

>
> On Monday, August 28, 2017 at 3:52:54 PM UTC+2, Ain wrote:
>>
>> Hi
>>
>> Tested with 1.9 and got the same behaviour - first row is returned OK, 
>> the second returns error.
>>
>> Does anyone use prepared select statements sucessfully? With which 
>> DB/driver?
>> I'm sure that if my code is silly someone would have pointed it out so 
>> I'm wondering am I the only one trying to use prepared select statements...
>>
>>
>> TIA
>> ain
>>
>>
>>
>> On Thursday, August 17, 2017 at 12:03:47 AM UTC+3, Ain wrote:
>>>
>>> Hi
>>>
>>> I tried to use prepared statements and it works first time, but fails on 
>>> second query. Ie code like
>>>
>>> tx, err := db.Begin()
>>> if err != nil {
>>> log.Fatalf("Error starting tx: %v", err)
>>> }
>>> defer tx.Rollback()
>>> st, err := tx.Prepare("select foo from t where id=?")
>>> if err != nil {
>>> log.Fatalf("Error preparing stmnt: %v", err)
>>> }
>>> defer st.Close()
>>> var n int
>>> err = st.QueryRow(1).Scan()
>>> if err != nil {
>>> log.Fatalf("Error selecting(1): %v", err)
>>> }
>>> fmt.Println("[1] =", n)
>>> err = st.QueryRow(2).Scan()
>>> if err != nil {
>>> log.Fatalf("Error selecting(2): %v", err)
>>> }
>>> fmt.Println("[2] =", n)
>>>
>>> the first row value is printed OK but the second QueryRow fails with 
>>> "Error op_response:0" message (this is with Firebird driver 
>>> github.com/nakagami/firebirdsql). Both id's exist in the DB so single 
>>> row is expected for both executions.
>>> I also got error with "github.com/mattn/go-sqlite3" driver so I don't 
>>> think this is a driver specific issue... either I use it the wrong way or 
>>> there is a bug in the database/sql?
>>>
>>> go version go1.8.1 linux/amd64
>>>
>>> TIA
>>> ain
>>>
>>

-- 
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: database/sql - prepared select statements only work on first invocation

2017-08-28 Thread Ain
Hi

Tested with 1.9 and got the same behaviour - first row is returned OK, the 
second returns error.

Does anyone use prepared select statements sucessfully? With which 
DB/driver?
I'm sure that if my code is silly someone would have pointed it out so I'm 
wondering am I the only one trying to use prepared select statements...


TIA
ain



On Thursday, August 17, 2017 at 12:03:47 AM UTC+3, Ain wrote:
>
> Hi
>
> I tried to use prepared statements and it works first time, but fails on 
> second query. Ie code like
>
> tx, err := db.Begin()
> if err != nil {
> log.Fatalf("Error starting tx: %v", err)
> }
> defer tx.Rollback()
> st, err := tx.Prepare("select foo from t where id=?")
> if err != nil {
> log.Fatalf("Error preparing stmnt: %v", err)
> }
> defer st.Close()
> var n int
> err = st.QueryRow(1).Scan()
> if err != nil {
> log.Fatalf("Error selecting(1): %v", err)
> }
> fmt.Println("[1] =", n)
> err = st.QueryRow(2).Scan()
> if err != nil {
> log.Fatalf("Error selecting(2): %v", err)
> }
> fmt.Println("[2] =", n)
>
> the first row value is printed OK but the second QueryRow fails with 
> "Error op_response:0" message (this is with Firebird driver 
> github.com/nakagami/firebirdsql). Both id's exist in the DB so single row 
> is expected for both executions.
> I also got error with "github.com/mattn/go-sqlite3" driver so I don't 
> think this is a driver specific issue... either I use it the wrong way or 
> there is a bug in the database/sql?
>
> go version go1.8.1 linux/amd64
>
> TIA
> ain
>

-- 
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] database/sql - prepared select statements only work on first invocation

2017-08-16 Thread Ain
Hi

I tried to use prepared statements and it works first time, but fails on 
second query. Ie code like

tx, err := db.Begin()
if err != nil {
log.Fatalf("Error starting tx: %v", err)
}
defer tx.Rollback()
st, err := tx.Prepare("select foo from t where id=?")
if err != nil {
log.Fatalf("Error preparing stmnt: %v", err)
}
defer st.Close()
var n int
err = st.QueryRow(1).Scan()
if err != nil {
log.Fatalf("Error selecting(1): %v", err)
}
fmt.Println("[1] =", n)
err = st.QueryRow(2).Scan()
if err != nil {
log.Fatalf("Error selecting(2): %v", err)
}
fmt.Println("[2] =", n)

the first row value is printed OK but the second QueryRow fails with "Error 
op_response:0" message (this is with Firebird driver 
github.com/nakagami/firebirdsql). Both id's exist in the DB so single row 
is expected for both executions.
I also got error with "github.com/mattn/go-sqlite3" driver so I don't think 
this is a driver specific issue... either I use it the wrong way or there 
is a bug in the database/sql?

go version go1.8.1 linux/amd64

TIA
ain

-- 
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] Parsing base64 data with headers

2017-04-06 Thread Ain

neljapäev, 6. aprill 2017 14:51.13 UTC+3 kirjutas Konstantin Khomoutov:
>
> On Thu, 6 Apr 2017 04:00:20 -0700 (PDT) 
> Ain <ain.v...@gmail.com > wrote: 
>
> > 
> > ie there are some headers and then base64 encoded data. I suspect 
> > there might be some functions in the std lib which should be able to 
> > parse this and give me easy access to the headers and data but I just 
> > can't find it... it isn't mime/multipart, right? Perhaps something 
> > in the http client package? 
>
> Almost. 
>
> What you're dealing with is a typical set of headers of a so-called 
> "MIME-formatted" e-mail message followed by its body.  The usual set of 
> headers is missing (those 'From', 'To' etc) and that's why it looks 
> strange. 
>
> So you parse it like a regular mail message using the net/mail package 
> and then base64-decode its body. 
>
> The program (playground link is [1]) 
>


Thank you, that's exactly what I was looking for!


ain

-- 
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] Parsing base64 data with headers

2017-04-06 Thread Ain

neljapäev, 6. aprill 2017 14:07.13 UTC+3 kirjutas ehedgehog:
>
> On 6 April 2017 at 12:00, Ain <ain.v...@gmail.com > wrote: 
>
> > ie there are some headers and then base64 encoded data. I suspect there 
> > might be some functions in the std lib which should be able to parse 
> this 
> > and give me easy access to the headers and data but I just can't find 
> it... 
> > it isn't mime/multipart, right? Perhaps something in the http client 
> > package? 
>
> encoding/base64? 
>

Yes, it could be used to decode the base64 data, but the "message" I have 
has some headers in the beginning (which the encoding/base64 wouldn't 
handle AFAIK). I'm hoping that there is already some func which handles 
parsing such a message as is.


ain

 

>
> Chris 
>
> -- 
> Chris "allusive" Dollin 
>

-- 
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] sort.Slice arguments

2017-03-08 Thread Ain

Another, OO-ish fix is to use method on custom type 
(https://play.golang.org/p/a5S5rNog5h):

type itinerary []string

func (t itinerary) sort() {
sort.Slice(t, func(i, j int) bool {
return t[i] < t[j]
})
}

func main() {
itinerary := itinerary{"Philadelphia", "Chicago", "Boston", "Austin"}
itinerary[1:].sort()
fmt.Println("My new itinerary is", itinerary)
}


ain


On Wednesday, March 8, 2017 at 5:01:08 PM UTC+2, Val wrote:
>
> Sorry for not elaborating in the first place (I was trying to make the 
> point very concise).
>
> This is the starting city :  Philadelphia
>
> This are the other cities :   Chicago, Boston, Austin
>
> The itinerary is the concatenation of starting city + other cities to be 
> visited :   [Philadelphia, Chicago, Boston, Austin]
>
> In this contrived example the first city is fixed, because this is where I 
> am now, wherever I decide to go next. That's why I decide to reorder all 
> cities of my itinerary except the first one.
>
> This is what my naive code what trying to achieve (expected value of slice 
> itinerary after partial sort) : [Philadelphia Austin Boston Chicago]
>
> This is what the code actually produces (value of slice itinerary after 
> partial sort) : [Philadelphia Boston Chicago Austin] , which is why i say 
> it is broken : the last 3 items don't end up in alphabetical order like I 
> expected them to be.
>
> In a real program, there would be various legit reasons to sort only part 
> of a slice, and the items would not always have a builtin type like string, 
> rather custom struct types.
>
> @CBanning  Thanks, I had not thought of StringSlice!  But it's not 
> applicable in my real programs, which deal with custom struct types (not 
> strings).
>
> @David  Sorting the whole slice is not what I was trying to achieve, 
> because I can't change my starting point.
>
> The bug in my code is that the two arguments I pass to sort.Slice are 
> inconsistent : the portion to be sorted is a reslicing from itinerary, 
> while the "less" closure indexes items of the whole itinerary.
>
> I brought up the "go vet" idea because I feel that whenever someone will 
> do some reslicing directly in the first argument,
> - either the result will be "broken" like mine,
> - or the code in the less function will have to refer to the same 
> (unnamed) resliced portion, which is imo convoluted : fix 1 
> <https://play.golang.org/p/v0V8BQuJ_m> or fix 2 
> <https://play.golang.org/p/z_52IQAhY4> .
>
> The most readable alternative I can think of while still using sort.Slice 
> is to reslice in a new variable prior to sorting : fix 3 
> <https://play.golang.org/p/ZgHyGOLiQO> .
>
> Best regards
> Val
>
> On Wednesday, March 8, 2017 at 3:25:48 PM UTC+1, David Peacock wrote:
>>
>> On Wed, Mar 8, 2017 at 8:32 AM, Valentin Deleplace <dele...@gmail.com> 
>> wrote:
>>
>>> I did explain the expected result : "and I want to visit other cities 
>>> in alphabetical order"
>>>
>>
>> Jan is correct; the characterization of a problem hinges on accurately 
>> describing what you expect and what happened instead.  Terms such as 
>> "broken" and "does not work" are best avoided because others don't know 
>> what your definitions are for these in the given context. :-)
>>
>> That being said, your alphabetical order is returned as you intend if you 
>> adjust line 17 thusly:
>>
>> sort.Slice(itinerary[:], func(i, j int) bool {
>>
>> Cheers,
>> David
>>  
>>
>>>
>>> Le 8 mars 2017 2:16 PM, "Jan Mercl" <0xj...@gmail.com> a écrit :
>>>
>>>> On Wed, Mar 8, 2017 at 2:10 PM Val <dele...@gmail.com> wrote:
>>>>
>>>> > What do you think?
>>>>
>>>> You should explain what you've expected to get instead of what you've 
>>>> got. Without that, I for one, cannot figure out what you see as broken and 
>>>> I have no idea why do you think it's not a good idea to sort a slice of a 
>>>> slice. After all, it's just a slice as any other.
>>>>
>>>> -- 
>>>>
>>>> -j
>>>>
>>> -- 
>>> 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.
>>> 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: Get Excel Sheet Names

2017-01-26 Thread Ain

On Thursday, January 26, 2017 at 7:33:42 PM UTC+2, David Sofo wrote:
>
>
> Hi,
>
> I am using this Go library https://github.com/tealeg/xlsx to to read 
> excel file . Is there a way to get all sheets names? Thank you.
>

I have not used it myself but looking at the doc:

xlFile, err := xlsx.OpenFile(excelFileName)
for _, sheet := range xlFile.Sheets {
   fmt.Println(sheet.Name)
}



HTH
ain


 

>
> Regards
> David
>

-- 
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: HTTP server triggers 'Access-Control-Allow-Origin' header contains multiple values error

2016-12-06 Thread Ain

kolmapäev, 7. detsember 2016 0:30.12 UTC+2 kirjutas paul.h@gmail.com:
>
> We have a simple http service running using the net/http package and I 
> tried setting the Access-Control-Allow-Origin header value as in:
>
> w.Header().Set("Access-Control-Allow-Origin", "*")
>
> and when I do so the client side gets an error: "The 
> 'Access-Control-Allow-Origin' header contains multiple values"
>

And how the raw header looks like (at the client side)?


So it seems somewhere else the request origin is already added to the 
> header although I can't find any mention of this in the docs.
>

Do you use any http middleware / frameworks or is it plain net/http server?


ain 

-- 
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: "gcc": executable file not found in %PATH%

2016-09-18 Thread Ain
esmaspäev, 19. september 2016 8:48.37 UTC+3 kirjutas loc...@gmail.com:
>
> Hello again. I am trying to connect to a SQLite database with the package 
> # github.com/mattn/go-sqlite3 and get the aforementioned error whenever I 
> attempt to run my program. I am running a 32-bit Windows 10 OS and version 
> 1.7.1 of GoLang.
>
 
In the very top of the readme:

<<*go-sqlite3* is *cgo* package. If you want to build your app using 
go-sqlite3, you need gcc. However, if you install *go-sqlite3* withgo 
install github.com/mattn/go-sqlite3, you don't need gcc to build your app 
anymore.>> 

So how did you install the go-sqlite3 <http://github.com/mattn/go-sqlite3>, 
using "go get..." or "go install..."?


HTH
ain

-- 
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: adding aes128-cbc support to ssh.go

2016-09-14 Thread Ain
On Wednesday, September 14, 2016 at 3:17:19 PM UTC+3, viljo...@gmail.com 
wrote:
>
> Hi,
>
> To start off I'm fairly new to Go, I would just like to know the following:
>
> If I make changes similar to yours in common.go, how would I be able to 
> make use of them in my main package.
>
> For example in my common.go file I added the following
>  common.go 
> func returnCiphers() []string {
> return supportedCiphers
> }
>
> In my main package, how will I call it as the following does not seem to 
> work:
>  main.go 
> fmt.Println(ssh.returnCiphers())
>
> Assistance will greatly be appreciated.
>
>>
>>
Your function name starts with lower case character which means that it is 
not exported.


ain

 

-- 
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] Unmarshalling and tags

2016-06-21 Thread Ain

teisipäev, 21. juuni 2016 9:47.54 UTC+3 kirjutas rog:
>
> I feel your pain - we quite often have tags with entries for three 
> formats (JSON, YAML and BSON) - but I'm not sure that collapsing them 
> is necessarily a good idea, as the named tags indicate that the object 
> is explicitly intended to be able to be marshaled with those formats. 
>

Another idea is to allow the tags to be defined by more than one string:

type Payment struct { 
ActionType paypal.ActionType `xml:"actionType,omitempty"` 
 `json:"action"`
ReceiverList paypal.ReceiverList 
`xml:"receiverList,omitempty"`  `json:"receiver"`
} 

compiler would concatenate them into single string so all code will 
continue to work but this would allow the gofmt to align them into neat 
columns, making it easier to read.


ain 

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