[go-nuts] Re: appengine golang logs

2017-11-03 Thread Jim Cote
In appengine you have to use google.golang.org/appengine/log package.  The 
log calls must have a context passed to it.

See https://cloud.google.com/appengine/docs/standard/go/logs/reference.


On Friday, November 3, 2017 at 3:58:34 AM UTC-4, Sankar wrote:
>
> Hi
>
>
> I have a golang file where I have code like:
>
>
> log.Fatal("My error message: ", err)
>
>
> When the above statement is executed, In the appengine logviewer, I get 
> something like:
>
> panic: os.Exit called goroutine 1 [running]: 
> os.Exit(0x1)
> go/src/os/proc.go:58 
> 
>  
> +0x7c log.Fatal(0xc008549f60, 0x2, 0x2) 
> go/src/log/log.go:303 
> 
>  
> +0x79 main.main()
> main.go:42 
> 
>  
> +0x201
>
> But I dont get any error message. The main.go:42 corresponds to the 
> log.Fatal line in my code but I do not get to see the error message that is 
> printed as part of the log statement.
>
> I see that appengine package has a "Log" function which may print the 
> AppLogs such that they can be viewed from the Google Appengine log console 
> itself.
>
> My question is, can the golang default log package be somehow instructed 
> to redirect to appengine ? Something like:
>
> if env == "AppEngine" {
>   log.SetOutput(appengine.DefaultLogger) 
> }
>
> in my main file ? This way, I get to make my code not locked to google 
> cloud and also can deploy existing code which uses log already.
>
> Any pointers ?
>
> 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: time.Parse with millisecond separated by colon

2017-10-30 Thread Jim Cote
See https://golang.org/src/time/format.go?s=23626:23672#L249.  The standard 
library is explicitly looking for the period.  Your easiest solution would 
be to just write your own parser.

On Monday, October 30, 2017 at 11:20:51 AM UTC-4, Diego Medina wrote:
>
> Hi,
>
> I need to parse datetime data given in a csv file, the format I get (I get 
> a lot of diff ones but the latest is):
>
> 20060102 15:04:05:000
>
> but if I use that with time.Parse, it doesn't parse the millisecond part, 
> tells me:
>
> parsing time "20170628 12:11:00:103" as "20060102 15:04:05:000": cannot parse 
> "103" as ":000"
>
>
>
> if I change the format, from :000 to .000 and then change my source time, 
> to be  12:11:00.103
>
> it does parse. Is there a way to avoid having to edit the source file, so 
> I can just take the datetime info as it is in the file?
>
> playground example:
>
> https://play.golang.org/p/cHTDxFYmrF
>
> Thanks
>
> Diego
>

-- 
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: dynamic xml

2017-10-19 Thread Jim Cote
You'll need to use an UnmarshalXML func for the params:

// Param is a tag w/ any name
type Param struct {
Namestring `xml:"-"`
Typestring `xml:"type,attr"`
MinOccurs   int`xml:"minOccurs,attr"`
MaxOccurs   int`xml:"maxOccurs,attr"`
Description string `xml:"description"`
}


// ParamList type for unmarhsal
type ParamList []Param


// UnmarshalXML for the win
func (pl *ParamList) UnmarshalXML(d *xml.Decoder, s xml.StartElement) error 
{
tk, err := d.Token()
for err == nil {
switch t := tk.(type) {
case xml.StartElement:
param := Param{Name: t.Name.Local}
if err = d.DecodeElement(, ); err != nil {
return err
}
*pl = append(*pl, param)
 }
 if tk, err = d.Token(); err == io.EOF {
 return nil
 }
}
return err
}


// TopLevel is of course top level
type TopLevel struct {
Description string   `xml:"description"`
Rights  Rights   `xml:"rights"`
Method  []Method `xml:"method"`
}


// Method has request
type Method struct {
Namestring   `xml:"name,attr"`
Description string   `xml:"description"`
Rights  []Right  `xml:"rights"`
Request Request  `xml:"request"`
ResponseResponse `xml:"response"`
}


// Right whatever
type Right struct {
Right string `xml:"right"`
}


// Request like Response
type Request struct {
Params ParamList `xml:"params"`
}


// Response like Request
type Response struct {
Params ParamList `xml:"params"`
}


// Rights 
type Rights struct {
PrivLevel string `xml:"privLevel"`
}


On Wednesday, October 18, 2017 at 11:50:45 AM UTC-4, Jeffrey Smith wrote:
>
> I have a lot of XML documents that have sections in that contain tags that 
> can be of any name but will contain type,minOccurs,maxOccurs and have a 
> description inside it. For instance name,description,definition and id 
> below.
>
>
>
> 
> 
>   description number1
>   
> user
>   
>   
> graphCreate API
> 
> 
>   
> 
>   A friendly name to identify the graph
> 
> 
>   Detailed description of the graph
> 
> 
>   Specify the graph definition. i.e how this graph 
> should be built.
> 
>   
> 
> 
>   
>
>   graph identifier.
> 
>   
> 
>   
>  
>
> Whats the best way to parse this. So far I have but can't work out how to 
> dynamically generate the struct to stuff this into. Any suggestions?
>
> type topLevel struct {
> Description string   `xml:"description"`
> Rights  rights   `xml:"rights"`
> Method  []method `xml:"method"`
> }
>
>
> type method struct {
> Namestring  `xml:"name,attr"`
> Description string  `xml:"description"`
> Rights  []right `xml:"rights"`
> }
>
>
> type right struct {
> Right string `xml:"right"`
> }
>
>
> type request struct {
> }
>
>
> type rights struct {
> PrivLevel string `xml:"privLevel"`
> }
>
>

-- 
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: dynamic xml

2017-10-19 Thread Jim Cote
You'll need to use a custom UnmarshalXML func to handle this.



// TopLevel is of course top level
type TopLevel struct {
 Description string   `xml:"description"`
 Rights  Rights   `xml:"rights"`
 Method  []Method `xml:"method"`
}


// Method has request
type Method struct {
 Namestring   `xml:"name,attr"`
 Description string   `xml:"description"`
 Rights  []Right  `xml:"rights"`
 Request Request  `xml:"request"`
 ResponseResponse `xml:"response"`
}


// Right whatever
type Right struct {
 Right string `xml:"right"`
}


// Request like Response
type Request struct {
 Params ParamList `xml:"params"`
}


// Response like Request
type Response struct {
 Params ParamList `xml:"params"`
}


// ParamList type for unmarhsal
type ParamList []Param


// UnmarshalXML for the win
func (pl *ParamList) UnmarshalXML(d *xml.Decoder, s xml.StartElement) error 
{
 tk, err := d.Token()
 for err == nil {
 switch t := tk.(type) {
 case xml.StartElement:
 var param = Param{Name: t.Name.Local}
 if err = d.DecodeElement(, ); err != nil {
 return err
 }
 *pl = append(*pl, param)
 }
 tk, err = d.Token()
 }
 return err
}


// Param holds data
type Param struct {
 Namestring `xml:"name"`
 Typestring `xml:"type,attr"`
 MinOccurs   int`xml:"minOccurs,attr"`
 MaxOccurs   int`xml:"maxOccurs,attr"`
 Description string `xml:"description"`
}


// Rights hmm
type Rights struct {
 PrivLevel string `xml:"privLevel"`
}


On Wednesday, October 18, 2017 at 11:50:45 AM UTC-4, Jeffrey Smith wrote:
>
> I have a lot of XML documents that have sections in that contain tags that 
> can be of any name but will contain type,minOccurs,maxOccurs and have a 
> description inside it. For instance name,description,definition and id 
> below.
>
>
>
> 
> 
>   description number1
>   
> user
>   
>   
> graphCreate API
> 
> 
>   
> 
>   A friendly name to identify the graph
> 
> 
>   Detailed description of the graph
> 
> 
>   Specify the graph definition. i.e how this graph 
> should be built.
> 
>   
> 
> 
>   
>
>   graph identifier.
> 
>   
> 
>   
>  
>
> Whats the best way to parse this. So far I have but can't work out how to 
> dynamically generate the struct to stuff this into. Any suggestions?
>
> type topLevel struct {
> Description string   `xml:"description"`
> Rights  rights   `xml:"rights"`
> Method  []method `xml:"method"`
> }
>
>
> type method struct {
> Namestring  `xml:"name,attr"`
> Description string  `xml:"description"`
> Rights  []right `xml:"rights"`
> }
>
>
> type right struct {
> Right string `xml:"right"`
> }
>
>
> type request struct {
> }
>
> Enter code here...
>
>
> type rights struct {
> PrivLevel string `xml:"privLevel"`
> }
>
>

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