Tong Sun | 27 Jun 22:16 2015
Picon

Is it possible to use text/template and html/template interchangeably

Hi, 

Is it possible to use text/template and html/template interchangeably? 

I want to do something like this:

import (
ht "html/template"
tt "text/template"
)

then, 

        var t something_like_interface{}_or
if opts.Html {
t := ht.New("H")
} else {
t := tt.New("T")
}

        t.ParseFiles... 

Is there any way to make it possible?

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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Tong Sun | 27 Jun 21:38 2015
Picon

Parse from a template file

Hi, 

How to parse from a template file?

http://blog.zmxv.com/2011/09/go-template-examples.html says:

t, _ := template.New("template_name").ParseFile("external.file")

but .ParseFile is undefined now. 

http://golangtutorials.blogspot.ca/2011/06/go-templates.html says:

t, _ = t.ParseFiles("tmpl/welcome.html", nil) //open and parse a template text file

But I got:

  cannot use nil as type string in argument to template.New("T").ParseFiles

I tried to remove the ", nil" part, as, 

t := template.New("T").ParseFiles(file + ".tmpl")

but got:

  multiple-value template.New("T").ParseFiles() in single-value context

Please help. 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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
will | 27 Jun 20:44 2015
Picon

upload large files to web server using golang

Hi gophers,

How does one upload large files (>500mb) to a golang web server?

kind regards,

Will

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Tong Sun | 27 Jun 20:38 2015
Picon

How to put flag variables into a structure

Hi, 

I still haven't figure out what's the ideal way to put flag variables into a structure. Can someone show me please? 

You can use the code posted in 
https://sfxpt.wordpress.com/2015/06/18/passing-options-to-go-from-command-line/
as the starting point if you like. 

I.e., the code of
https://github.com/suntong001/lang/blob/master/lang/Go/src/sys/CommandLineFlag.go

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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Danver Braganza | 27 Jun 20:22 2015
Picon

Show Golang-nuts: Varcaser, a library to convert between variable casing conventions

Hey Nuts,

I wanted to show you a library I created driven by a need I had to convert between different variable case conventions. If you ever find yourself manipulating code or data, and need to transform symbols between different variable case conventions, this might be of use to you.

The library is made available under the LGPL v3 license at https://github.com/danverbraganza/varcaser 

result := Caser{From: LowerCamelCase, To: KebabCase}.String("someInitMethod") // "some-init-method" result := Caser{From: LowerCamelCase, To: ScreamingSnakeCase}.String("myConstantVariable") // "MY_CONSTANT_VARIABLE"Hope you find this useful, and any feedback is welcome.Cheers, Danver Braganza

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Tong Sun | 27 Jun 20:04 2015
Picon

Templating a list in Go

Hi, 

If I want to list out things in Go Template like this:

    The colors are: {{range .Colors}}{{.}}, {{end}}.

Then there will always be a trialing "," at the end of the list. 

Is there any easy way to suppress such trialing "," at the end of the list please? 

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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Tong Sun | 27 Jun 19:52 2015
Picon

Pass back quote characters from Yaml to Go

Hi, 

The double quote characters are silently removed from the Yaml during `yaml.Unmarshal`. For e.g., for a Yaml string of:

const data = `
A: Easy!
B:
  C: 2
  D: ["3A", "4B"]
`

After `yaml.Unmarshal`, it becomes `D:[3A 4B]`. I.e., the quote characters are missing. 

Is there any ways to still retain the quote characters?

The full source code is from
https://github.com/go-yaml/yaml

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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Tong Sun | 27 Jun 18:46 2015
Picon

Go templating from map from Yaml

Hi, 

I have a `m := make(map[interface{}]interface{})` with the following data:

map[B:map[C:2 D:[3 4]] Colors1:[red blue] Colors2:[red blue] H:[map[Name:Xavier Age:24] map[Name:Xavier2 Age:22]] A:Easy!]

--- m dump:
A: Easy!
B:
  C: 2
  D:
  - 3
  - 4
Colors1:
- red
- blue
Colors2:
- red
- blue
H:
- Age: 24
  Name: Xavier
- Age: 22
  Name: Xavier2

I want to use it to template the following:

const templ = `Templating from Yaml with Go is {{.A}}.
{{range .H}}
  The name is {{.Name}}.
  The age is {{.Age}}.
{{end}}
`

But I got:

  Templating from Yaml with Go is Fatal error  template: Test template:1:34: executing "Test template" at <.A>: can't evaluate field A in type []uint8

I think I'm pretty close, but don't know what goes wrong. Please help. 
The full source code is posted at http://pastie.org/10261836

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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
agj32mrgibbits | 27 Jun 10:54 2015
Picon

go 1.4, using hash/crc32 with crypto/hmac gives incorrect sum

The sum for string "test" with key "test" and polynomial IEEE should give a sum of "3b5bb714", but instead it gives "f7f3ea7d".

See here: http://play.golang.org/p/6AEtZh7lwt

Am I doing something wrong? Is there an easy way to remedy this?

Highly appreciate anyone taking the time to look at this.

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
proctertenpointfour | 27 Jun 12:11 2015
Picon

Go markdown blog

to be fair Ive not done much digging / reading yet and so am just hoping someone can kickstart me.  code so far
can be found here - https://github.com/adamprocter/gomarkdownblog - I am now at a stage where I really
need the index page to be organisable via date not the default file name via {{. range}}   The date I want to use
is found in the post as {{.Date}}  but could be a new field - thanks in advance.  

Also I’m off to go lang uk but is there any current go documentation people would really really recommend,
the tour for me feels a little too removed from making stuff and more about the principles and so I am
struggling a bit

--

-- 
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+unsubscribe@...
For more options, visit https://groups.google.com/d/optout.
Prashant Shah | 26 Jun 20:28 2015
Picon

maps of maps

Hi,

How do I declare something like this in golang ?

$a = {
    "string1" =>
    {
        "type" => "monitor",
        "length" => "10",
        ....
    }
    "string2" =>
    {
        "type" => "keyboard",
        "length" => "12",
        ....
    }
};

Regards.

--

-- 
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+unsubscribe@...
For more options, visit https://groups.google.com/d/optout.


Gmane