當前位置: 首頁>>代碼示例>>Golang>>正文


Golang CherryRooms.PortBusyByAnotherRoom方法代碼示例

本文整理匯總了Golang中pkg/config.CherryRooms.PortBusyByAnotherRoom方法的典型用法代碼示例。如果您正苦於以下問題:Golang CherryRooms.PortBusyByAnotherRoom方法的具體用法?Golang CherryRooms.PortBusyByAnotherRoom怎麽用?Golang CherryRooms.PortBusyByAnotherRoom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pkg/config.CherryRooms的用法示例。


在下文中一共展示了CherryRooms.PortBusyByAnotherRoom方法的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
}
開發者ID:rafael-santiago,項目名稱:cherry,代碼行數:100,代碼來源:parser.go


注:本文中的pkg/config.CherryRooms.PortBusyByAnotherRoom方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。