gocal | ICS file parser in Golang
kandi X-RAY | gocal Summary
kandi X-RAY | gocal Summary
Fast (and opinionated) ICAL parser in Golang. Gocal takes an io.Reader and produces an array of Events from it. Event are parsed between two given dates (Gocal.Start and Gocal.End, 3 months by default). Any event outside this range will be ignored. This behavior can be disabled by setting SkipBounds to true in the Gocal struct. Please note that the behavior will still be enacted for recurring event, to prevent infinite parsing.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- parseEvent handles an event
- ParseTime - parses string to time . Time
- parseDayNameToIcsName converts a day name to ics name .
- LoadTimezone loads timezone from tzid
- ParseGeo returns the latitude and longitude longitude .
- Example for example
- ParseRecurrenceParams parses a sequence of params
- ParseParameters takes a string and returns a map of parameters
- NewParser returns Gocal instance
- ParseDuration is like ParseDuration .
gocal Key Features
gocal Examples and Code Snippets
Community Discussions
Trending Discussions on gocal
QUESTION
I would like to parse several times with gocal
data I retrieve through a HTTP call. Since I would like to avoid making the call for each of the parsing, I would like to save this data and reuse it.
The Body
I get from http.Get
is of type io.ReadCloser
. The gocal
parser requires io.Reader
so it works.
Since I can retrieve Body
only once, I can save it with body, _ := io.ReadAll(get.Body)
but then I do not know how to serve []byte
as io.Reader
back (to the gocal
parser, several times to account for different parsing conditions)
ANSWER
Answered 2021-Aug-14 at 16:33As you have figured, the http.Response.Body
is exposed as an io.Reader
, this reader is not re usable because it is connected straight to the underlying connection* (might be tcp/utp/or any other stream like reader under the net package).
Once you read the bytes out of the connection, new bytes are sitting their waiting for another read.
In order to save the response, indeed, you need to drain it first, and save that result within a variable.
body, _ := io.ReadAll(get.Body)
To re use that slice of bytes many time using the Go programming language, the standard API provides a buffered reader bytes.NewReader
.
This buffer adequately offers the Reset([]byte)
method to reset the state of the buffer.
The bytes.Reader.Reset
is very useful to read multiple times the same bytes buffer with no allocations. In comparison, bytes.NewReader
allocates every time it is called.
Finally, between two consecutive calls to c.Parser
, you should reset the buffer with bytes buffer you have collected previously.
such as :
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install gocal
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page