You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gophi/gopher/filecontents.go

38 lines
1.0 KiB
Go

package gopher
import (
"gophi/core"
"os"
)
// gophermapContents is an implementation of core.FileContents that holds individually renderable sections of a gophermap
type gophermapContents struct {
sections []gophermapSection
}
// WriteToClient renders each cached section of the gophermap, and writes them to the client
func (gc *gophermapContents) WriteToClient(client *core.Client, path *core.Path) core.Error {
// Render + write the sections!
for _, section := range gc.sections {
err := section.RenderAndWrite(client)
if err != nil {
return err
}
}
// Finally, write the footer (including last-line)
return client.Conn().Write(footer)
}
// Load takes an open FD and loads the gophermap contents into memory as different renderable sections
func (gc *gophermapContents) Load(fd *os.File, path *core.Path) core.Error {
var err core.Error
gc.sections, err = readGophermap(fd, path)
return err
}
// Clear empties currently cached GophermapContents memory
func (gc *gophermapContents) Clear() {
gc.sections = nil
}