本文整理汇总了Golang中pkg/config.CherryRooms.SetCertificatePath方法的典型用法代码示例。如果您正苦于以下问题:Golang CherryRooms.SetCertificatePath方法的具体用法?Golang CherryRooms.SetCertificatePath怎么用?Golang CherryRooms.SetCertificatePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pkg/config.CherryRooms
的用法示例。
在下文中一共展示了CherryRooms.SetCertificatePath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ParseCherryFile
// ParseCherryFile parses a file at @filepath and returns a *config.CherryRooms or a *CherryFileError.
func ParseCherryFile(filepath string) (*config.CherryRooms, *CherryFileError) {
var cherryRooms *config.CherryRooms
var cherryFileData []byte
var data string
var err *CherryFileError
var line int
cherryFileData, ioErr := ioutil.ReadFile(filepath)
if ioErr != nil {
return nil, NewCherryFileError("(no file)", -1, fmt.Sprintf("unable to read from \"%s\" [more details: %s].", filepath, ioErr.Error()))
}
data, _, line, err = GetDataFromSection("cherry.root", string(cherryFileData), 1, filepath)
if err != nil {
return nil, err
}
var set []string
cherryRooms = config.NewCherryRooms()
set, line, data = GetNextSetFromData(data, line, "=")
for len(set) == 2 {
switch set[0] {
case "servername", "certificate", "private-key":
if set[1][0] != '"' || set[1][len(set[1])-1] != '"' {
return nil, NewCherryFileError(filepath, line, fmt.Sprintf("invalid string."))
}
data := set[1][1 : len(set[1])-1]
if set[0] == "certificate" || set[0] == "private-key" {
if _, err := os.Stat(data); os.IsNotExist(err) {
return nil, NewCherryFileError(filepath, line, fmt.Sprintf("\"%s\" must receive an accessible file path.", set[0]))
}
}
if set[0] == "servername" {
cherryRooms.SetServername(data)
} else if set[0] == "certificate" {
cherryRooms.SetCertificatePath(data)
} else if set[0] == "private-key" {
cherryRooms.SetPrivateKeyPath(data)
}
break
default:
return nil, NewCherryFileError(filepath, line, fmt.Sprintf("unknown config set \"%s\".", set[0]))
}
set, line, data = GetNextSetFromData(data, line, "=")
}
if cherryRooms.GetServername() == "localhost" {
fmt.Println("WARN: cherry.root.servername is equals to \"localhost\". Things will not work outside this node.")
}
data, _, line, err = GetDataFromSection("cherry.rooms", string(cherryFileData), 1, filepath)
if err != nil {
return nil, err
}
// INFO(Santiago): Adding all scanned rooms from the first cherry.rooms section found
// [cherry branches were scanned too at this point].
set, line, data = GetNextSetFromData(data, line, ":")
for len(set) == 2 {
if cherryRooms.HasRoom(set[0]) {
return nil, NewCherryFileError(filepath, line, fmt.Sprintf("room \"%s\" redeclared.", set[0]))
}
var value int64
var convErr error
value, convErr = strconv.ParseInt(set[1], 10, 16)
if convErr != nil {
return nil, NewCherryFileError(filepath, line, fmt.Sprintf("invalid port value \"%s\" [more details: %s].", set[1], convErr))
}
var port int16
port = int16(value)
if cherryRooms.PortBusyByAnotherRoom(port) {
return nil, NewCherryFileError(filepath, line, fmt.Sprintf("the port \"%s\" is already busy by another room.", set[1]))
}
cherryRooms.AddRoom(set[0], port)
errRoomConfig := GetRoomTemplates(set[0], cherryRooms, string(cherryFileData), filepath)
if errRoomConfig != nil {
return nil, errRoomConfig
}
errRoomConfig = GetRoomActions(set[0], cherryRooms, string(cherryFileData), filepath)
if errRoomConfig != nil {
return nil, errRoomConfig
}
// INFO(Santiago): until now these two following sections are non-mandatory.
_ = GetRoomImages(set[0], cherryRooms, string(cherryFileData), filepath)
//_ = GetRoomSounds(set[0], cherryRooms, string(cherryFileData), filepath)
errRoomConfig = GetRoomMisc(set[0], cherryRooms, string(cherryFileData), filepath)
if errRoomConfig != nil {
return nil, errRoomConfig
}
// INFO(Santiago): Let's transfer the next room from file to the memory.
set, line, data = GetNextSetFromData(data, line, ":")
}
return cherryRooms, nil
}