// GetRoomTemplates parses "cherry.[roomName].templates" section. func GetRoomTemplates(roomName string, cherryRooms *config.CherryRooms, configData, filepath string) *CherryFileError { var data string var line int var err *CherryFileError data, _, line, err = GetDataFromSection("cherry."+roomName+".templates", configData, 1, filepath) if err != nil { return err } var set []string set, line, data = GetNextSetFromData(data, line, "=") for len(set) == 2 { if cherryRooms.HasTemplate(roomName, set[0]) { return NewCherryFileError(filepath, line, "room template \""+set[0]+"\" redeclared.") } if len(set[1]) == 0 { return NewCherryFileError(filepath, line, "room template with no value.") } if set[1][0] != '"' || set[1][len(set[1])-1] != '"' { return NewCherryFileError(filepath, line, "room template must be set with a valid string.") } var templateData []byte var templateDataErr error templateData, templateDataErr = ioutil.ReadFile(set[1][1 : len(set[1])-1]) if templateDataErr != nil { return NewCherryFileError(filepath, line, "unable to access room template file [more details: "+templateDataErr.Error()+"].") } cherryRooms.AddTemplate(roomName, set[0], string(templateData)) set, line, data = GetNextSetFromData(data, line, "=") } return nil }