示例#1
0
文件: unit.go 项目: karlek/sensou
// Returns a unit struct initiated with the raw codes
func NewUnit(baseRawCode, customRawCode string) (unit *Unit, err error) {
	if temp.IsRawCode(baseRawCode) == false {
		return nil, errorsutil.Errorf("Invalid base unit rawcode: %s - must be upper or lowercase alpha numeric and 4 characters long", baseRawCode)
	} else if temp.IsRawCode(customRawCode) == false {
		return nil, errorsutil.Errorf("Invalid custom unit rawcode: %s - must be upper or lowercase alpha numeric and 4 characters long", customRawCode)
	}

	return &Unit{BaseRawCode: baseRawCode, CustomRawCode: customRawCode}, nil
}
示例#2
0
文件: w3u.go 项目: karlek/sensou
func GetRawCode(buffer *bytes.Buffer) (rawCode string, err error) {
	rawCode = string(buffer.Next(4))
	if !temp.IsRawCode(rawCode) {
		return "", errorsutil.Errorf("Illegal raw code: [% X]", rawCode)
	}

	return rawCode, nil
}
示例#3
0
文件: unit.go 项目: karlek/sensou
// Adds a new field to the unit
func (unit *Unit) AddField(fieldRawCode string, value interface{}) (err error) {
	if temp.IsRawCode(fieldRawCode) == false {
		return errorsutil.Errorf("Invalid field rawcode: %s - must be upper or lowercase alpha numeric and 4 characters long", fieldRawCode)
	}

	unit.Fields = append(unit.Fields, field.Field{Name: fieldRawCode, Value: value})
	return nil
}