Documentation ¶
Index ¶
- func CreateRouter(fm FileManager) *mango.Router
- func ListenAndServe(rootpath string, webpath string, webfs fs.FS, port string)
- type FileDetails
- type FileManager
- type FileUpdater
- type ListHandlerState
- func (lh *ListHandlerState) AddItem(itemToAdd ListItem, listHolder ListHolder, c *mango.Context, listname string) error
- func (lh *ListHandlerState) AddItemWithContextBind(itemToAdd ListItem, listHolder ListHolder, c *mango.Context, listname string)
- func (lh *ListHandlerState) DeleteItem(itemToDelete ListItem, listHolder ListHolder, c *mango.Context, ...)
- func (lh *ListHandlerState) GetList(listHolder ListHolder, c *mango.Context, listname string)
- type ListHolder
- type ListItem
- type ParseBody
- type Persistable
- type PersistableHandlerState
- func (ph *PersistableHandlerState) GetObject(obj Persistable, c *mango.Context)
- func (ph *PersistableHandlerState) UpdateObject(obj Persistable, savedObj Updateable, c *mango.Context) error
- func (ph *PersistableHandlerState) UpdateObjectWithContextBind(obj Persistable, savedObj Updateable, c *mango.Context)
- type RunSpec
- type SimHandler
- type SimHandlerState
- func (sh *SimHandlerState) DeleteStep(c *mango.Context)
- func (sh *SimHandlerState) EncodeStepList(listHolder ListHolder, listname string) (interface{}, error)
- func (sh *SimHandlerState) GenerateNetwork(siminfo *SimInfo, c *mango.Context)
- func (sh *SimHandlerState) Get(c *mango.Context)
- func (sh *SimHandlerState) GetResults(c *mango.Context)
- func (sh *SimHandlerState) GetResultsCsv(c *mango.Context)
- func (sh *SimHandlerState) GetStepsOrResults(c *mango.Context)
- func (sh *SimHandlerState) ParseNetwork(siminfo *SimInfo, c *mango.Context)
- func (sh *SimHandlerState) PostRun(siminfo *SimInfo, c *mango.Context)
- func (sh *SimHandlerState) Put(c *mango.Context)
- func (sh *SimHandlerState) Register(r *mango.Router)
- func (sh *SimHandlerState) RunGenerateParseNetwork(c *mango.Context)
- type SimInfo
- type SimList
- type SimListExt
- type SimListHandler
- type SimListHandlerState
- func (sh *SimListHandlerState) AddSimulation(c *mango.Context)
- func (sh *SimListHandlerState) DeleteSimulation(c *mango.Context)
- func (sh *SimListHandlerState) EncodeFunc(listHolder ListHolder, listname string) (interface{}, error)
- func (sh *SimListHandlerState) GetSimulations(c *mango.Context)
- func (sh *SimListHandlerState) Register(r *mango.Router)
- func (sh *SimListHandlerState) UpdateNotes(c *mango.Context)
- type SimStep
- type StaticRouter
- type StepHandler
- type StepHandlerState
- type TimestampHolder
- type Updateable
- type UpdaterRepo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateRouter ¶
func CreateRouter(fm FileManager) *mango.Router
CreateRouter registers the route handlers. This function allows the route handlers to be tested with the mango.Browser
func ListenAndServe ¶
ListenAndServe launches the web server rootpath is the root directory where data served by this server is persisted webpath is the root directory of the static website served by this server webfs is the embedded copy of the static website that will be served if the webpath is an empty string port is the port to listen on
Types ¶
type FileDetails ¶
FileDetails contains information about a file that will be managed by the FileUpdater
func (*FileDetails) Create ¶
func (fd *FileDetails) Create(obj Persistable) error
Create creates a file and saves the supplied object into the file identified by path It returns the FileUpdater that should be used to access the file
func (*FileDetails) Delete ¶
func (fd *FileDetails) Delete() error
Delete the file on the file system
func (*FileDetails) Read ¶
func (fd *FileDetails) Read(obj Persistable) error
Read the file and unmarshal it into the supplied object. If the file hasn't changed since it was last read this function will do nothing. If the file is re-read then the Timestamp on the supplied object is updated
func (*FileDetails) Update ¶
func (fd *FileDetails) Update(obj Persistable) error
Update the contents of the file with the supplied persistable object. If the write to the file is successful, then the Timestamp of the persistable is updated too.
type FileManager ¶
type FileManager interface {
Get(path string) FileUpdater
}
FileManager is a repository for all instances of FileUpdater
func NewFileManager ¶
func NewFileManager(rootpath string) FileManager
NewFileManager returns a new instance of FileManager
type FileUpdater ¶
type FileUpdater interface { Create(obj Persistable) error Read(obj Persistable) error Update(obj Persistable) error Delete() error Path() string }
FileUpdater manages a file and provides Read and Update methods that allow the rest of the package to read and update a file. FileUpdater contains a lock to prevent multiple goroutines from trying to write at the same time and also prevents Reads from occuring whilst an update is being performed. The Update function checks the last modified time of the file before it updates it, if it has been modified since the last copy was read, then Update will return an error, and the Update method will attempt to re-read the contents of the file into the object supplied.
type ListHandlerState ¶
type ListHandlerState struct { FileManager FileManager EncodeFunc func(ListHolder, string) (interface{}, error) }
ListHandlerState holds state information for a ListHandler
func (*ListHandlerState) AddItem ¶
func (lh *ListHandlerState) AddItem(itemToAdd ListItem, listHolder ListHolder, c *mango.Context, listname string) error
AddItem adds the passed item to the specified list on the passed listholder
func (*ListHandlerState) AddItemWithContextBind ¶
func (lh *ListHandlerState) AddItemWithContextBind(itemToAdd ListItem, listHolder ListHolder, c *mango.Context, listname string)
AddItemWithContextBind binds the itemToAdd to the object passed in the mango context and adds it to the specified list on the passed listholder
func (*ListHandlerState) DeleteItem ¶
func (lh *ListHandlerState) DeleteItem(itemToDelete ListItem, listHolder ListHolder, c *mango.Context, listname string)
DeleteItem removes an item from the specified list on the passed listholder
func (*ListHandlerState) GetList ¶
func (lh *ListHandlerState) GetList(listHolder ListHolder, c *mango.Context, listname string)
GetList returns the list of items
type ListHolder ¶
type ListHolder interface { Persistable GetItems(listname string) []string UpdateItems(listname string, items []string) }
ListHolder is an interface that any persistable that contains a list must implement
type ListItem ¶
type ListItem interface { Persistable RelPath() string }
ListItem is an interface that any persistable that can be added to a list must implement
type ParseBody ¶
type ParseBody struct { sim.ParseOptions Payload []byte }
ParseBody is the payload struct for uploading a network in a text file to be parsed together with the options that specify how to parse the text file
type Persistable ¶
Persistable must be implemented by any obj that requires to be saved in a file using FileUpdater
type PersistableHandlerState ¶
type PersistableHandlerState struct {
FileManager FileManager
}
PersistableHandlerState holds state information for a PersistableHandlerState
func (*PersistableHandlerState) GetObject ¶
func (ph *PersistableHandlerState) GetObject(obj Persistable, c *mango.Context)
GetObject returns the object
func (*PersistableHandlerState) UpdateObject ¶
func (ph *PersistableHandlerState) UpdateObject(obj Persistable, savedObj Updateable, c *mango.Context) error
UpdateObject updates the saved copy of the passed object
func (*PersistableHandlerState) UpdateObjectWithContextBind ¶
func (ph *PersistableHandlerState) UpdateObjectWithContextBind(obj Persistable, savedObj Updateable, c *mango.Context)
UpdateObjectWithContextBind updates the saved copy of the passed object
type RunSpec ¶
RunSpec specifies the number of simulation steps to run, and the number of iterations that should be performed within each step
type SimHandler ¶
type SimHandler interface { mango.Registerer Get(c *mango.Context) Put(c *mango.Context) GetStepsOrResults(c *mango.Context) GetResults(c *mango.Context) RunGenerateParseNetwork(c *mango.Context) PostRun(siminfo *SimInfo, c *mango.Context) GenerateNetwork(siminfo *SimInfo, c *mango.Context) DeleteStep(c *mango.Context) }
SimHandler provides Read/Update methods for simulations on the simulation list
func NewSimHandler ¶
func NewSimHandler(fm FileManager) SimHandler
NewSimHandler returns a new instance of SimHandler
type SimHandlerState ¶
type SimHandlerState struct { ListHandlerState PersistableHandlerState }
SimHandlerState holds state data for the SimHandler
func (*SimHandlerState) DeleteStep ¶
func (sh *SimHandlerState) DeleteStep(c *mango.Context)
DeleteStep removes a simulation from the list of simulations
func (*SimHandlerState) EncodeStepList ¶
func (sh *SimHandlerState) EncodeStepList(listHolder ListHolder, listname string) (interface{}, error)
func (*SimHandlerState) GenerateNetwork ¶
func (sh *SimHandlerState) GenerateNetwork(siminfo *SimInfo, c *mango.Context)
GenerateNetwork generates a hierarchical network to be simulated.
func (*SimHandlerState) Get ¶
func (sh *SimHandlerState) Get(c *mango.Context)
Get returns an existing simulation
func (*SimHandlerState) GetResults ¶
func (sh *SimHandlerState) GetResults(c *mango.Context)
GetResults returns a concatenated set of results from all the steps in this simulation in JSON format
func (*SimHandlerState) GetResultsCsv ¶
func (sh *SimHandlerState) GetResultsCsv(c *mango.Context)
GetResultsCsv returns a concatenated set of results from all the steps in this simulation in text/csv format
func (*SimHandlerState) GetStepsOrResults ¶
func (sh *SimHandlerState) GetStepsOrResults(c *mango.Context)
GetStepsOrResults gets the list of steps in this simulation
func (*SimHandlerState) ParseNetwork ¶
func (sh *SimHandlerState) ParseNetwork(siminfo *SimInfo, c *mango.Context)
ParseNetwork parses a network from a text file uploaded in the body of the post. The network is modified according to the options already stored in the simulation and then set as the starting point for the simulation. This will throw if a the simulation already has steps.
func (*SimHandlerState) PostRun ¶
func (sh *SimHandlerState) PostRun(siminfo *SimInfo, c *mango.Context)
PostRun adds a new step to the list of simulations
func (*SimHandlerState) Put ¶
func (sh *SimHandlerState) Put(c *mango.Context)
Put updates an existing simulation
func (*SimHandlerState) Register ¶
func (sh *SimHandlerState) Register(r *mango.Router)
Register the routes for this routehandler
func (*SimHandlerState) RunGenerateParseNetwork ¶
func (sh *SimHandlerState) RunGenerateParseNetwork(c *mango.Context)
RunGenerateParseNetwork handles three possible routes: /simulation/{id}/run Runs the simulation for the specified number of steps and iterations. /simulation/{id}/generate Generates a network to simulate, this will throw if the simulation already has steps. /simulation/{id}/parse Parses a network specified in a text file and sets it as the network to simulate. This will throw if the simulation already has steps.
type SimInfo ¶
type SimInfo struct { TimestampHolder ID string `json:"id"` Name string `json:"name"` Description string `json:"description"` Steps []string `json:"steps"` Options sim.NetworkOptions `json:"options"` }
SimInfo contains all relevant information about a simulation
func CreateSimInfo ¶
func CreateSimInfo() *SimInfo
CreateSimInfo creates a new SimInfo object with a new ID
func NewSimInfo ¶
NewSimInfo returns a SimInfo object for the passed ID
func (*SimInfo) CopyValues ¶
func (si *SimInfo) CopyValues(obj Persistable) error
CopyValues copies the values from the passed SimStep object to this object. Returns an error if the values could not be copied
func (*SimInfo) UpdateItems ¶
UpdateItems updates the items in the specified list
type SimList ¶
type SimList struct { TimestampHolder Items []string `json:"simulations"` Notes string `json:"notes"` }
SimList is the list of simulations in the root directory
func NewSimList ¶
func NewSimList() *SimList
NewSimList returns a SimList object that will be persisted
func (*SimList) CopyValues ¶
func (sl *SimList) CopyValues(obj Persistable) error
CopyValues copies the values from the passed SimStep object to this object. Returns an error if the values could not be copied
func (*SimList) UpdateItems ¶
UpdateItems updates the items in the specified list
type SimListExt ¶
type SimListExt struct { TimestampHolder Items []*SimInfo `json:"simulations"` Notes string `json:"notes"` }
SimListExt is the struct that embeds SimInfo objects into the SimList
type SimListHandler ¶
type SimListHandler interface { mango.Registerer GetSimulations(c *mango.Context) AddSimulation(c *mango.Context) UpdateNotes(c *mango.Context) DeleteSimulation(c *mango.Context) }
SimListHandler provides Create/Delete methods for simulations on the simulation list
func NewSimListHandler ¶
func NewSimListHandler(fm FileManager) SimListHandler
NewSimListHandler returns a new instance of SimListHandler
type SimListHandlerState ¶
type SimListHandlerState struct { ListHandlerState PersistableHandlerState }
SimListHandlerState holds state data for the SimListHandler
func (*SimListHandlerState) AddSimulation ¶
func (sh *SimListHandlerState) AddSimulation(c *mango.Context)
AddSimulation adds a new simulation to the list of simulations
func (*SimListHandlerState) DeleteSimulation ¶
func (sh *SimListHandlerState) DeleteSimulation(c *mango.Context)
DeleteSimulation removes a simulation from the list of simulations
func (*SimListHandlerState) EncodeFunc ¶
func (sh *SimListHandlerState) EncodeFunc(listHolder ListHolder, listname string) (interface{}, error)
func (*SimListHandlerState) GetSimulations ¶
func (sh *SimListHandlerState) GetSimulations(c *mango.Context)
GetSimulations gets the list of simulations
func (*SimListHandlerState) Register ¶
func (sh *SimListHandlerState) Register(r *mango.Router)
Register the routes for this routehandler
func (*SimListHandlerState) UpdateNotes ¶
func (sh *SimListHandlerState) UpdateNotes(c *mango.Context)
UpdateNotes updates the notes on the sim list
type SimStep ¶
type SimStep struct { TimestampHolder Network sim.RelationshipMgr `json:"network"` Results sim.Results `json:"results"` ID string `json:"id"` ParentID string `json:"parent"` }
SimStep holds the results of each simulation step
func CreateSimStep ¶
CreateSimStep creates a new SimStep object with a new ID
func NewSimStep ¶
NewSimStep returns a SimStep object for the passed ID that will be persisted in directory root
func NewSimStepFromRelPath ¶
NewSimStepFromRelPath returns a SimStep object extracting IDs from the relative path in the passed string
func (*SimStep) CopyValues ¶
func (ss *SimStep) CopyValues(obj Persistable) error
CopyValues copies the values from the passed SimStep object to this object. Returns an error if the values could not be copied
func (*SimStep) UnmarshalJSON ¶
UnmarshalJSON implements unmarshaling to make sure network is properly unmarshalled into sim.Network
type StaticRouter ¶
StaticRouter is a derived version of mango.Router that also serves an embedded copy of the orgnetsim UI
func (*StaticRouter) ServeHTTP ¶
func (sr *StaticRouter) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP Decides based on the route path whether to use the API router or an embedded file server that serves the static files of the embedded website
type StepHandler ¶
StepHandler provides Read/Update methods for steps of a simulation
func NewStepHandler ¶
func NewStepHandler(fm FileManager) StepHandler
NewStepHandler returns a new instance of StepHandler
type StepHandlerState ¶
type StepHandlerState struct {
PersistableHandlerState
}
StepHandlerState holds state data for the StepHandler
func (*StepHandlerState) Get ¶
func (sh *StepHandlerState) Get(c *mango.Context)
Get returns an existing step within a simulation
func (*StepHandlerState) Put ¶
func (sh *StepHandlerState) Put(c *mango.Context)
Put updates an existing step within a simulation
func (*StepHandlerState) Register ¶
func (sh *StepHandlerState) Register(r *mango.Router)
Register the routes for this routehandler
type TimestampHolder ¶
TimestampHolder holds the current timestamp on a persistable object
func (*TimestampHolder) Timestamp ¶
func (ts *TimestampHolder) Timestamp() time.Time
Timestamp of the persistable object
func (*TimestampHolder) UpdateTimestamp ¶
func (ts *TimestampHolder) UpdateTimestamp(t time.Time)
UpdateTimestamp of the persistable object
type Updateable ¶
type Updateable interface { Persistable CopyValues(objToCopy Persistable) error }
Updateable must be implemented by any persistable object that can be updated
type UpdaterRepo ¶
type UpdaterRepo struct { Rootpath string Repo map[string]FileUpdater Lock sync.Mutex DirLock sync.RWMutex }
UpdaterRepo contains all FileUpdaters in use in this instance
func (*UpdaterRepo) Get ¶
func (ur *UpdaterRepo) Get(path string) FileUpdater
Get a FileUpdater for the specifed path