Пример #1
0
func (t *Type) UnmarshalJSON(p []byte) (err error) {
	var raw string
	err = json.Unmarshal(p, &raw)
	if err != nil {
		return err
	}
	switch Type(strings.ToLower(raw)) {
	case Empty:
		*t = Empty
	case Wall:
		*t = Wall
	case Player:
		*t = Player
	case Battery:
		*t = Battery
	case Laser:
		*t = Laser
	default:
		return errors.New(fmt.Sprintf("%s is not a valid cell type", raw))
	}
	return nil
}
Пример #2
0
func (o *Orientation) UnmarshalJSON(p []byte) (err error) {
	var raw string
	err = json.Unmarshal(p, &raw)
	if err != nil {
		return err
	}
	switch strings.ToLower(raw) {
	case "north", "n":
		*o = North
	case "east", "e":
		*o = East
	case "south", "s":
		*o = South
	case "west", "w":
		*o = West
	default:
		// hmm, try as a number
		i, err := strconv.Atoi(raw)
		if err != nil {
			return err
		}
		switch Orientation(i) {
		case North:
			*o = North
		case East:
			*o = East
		case South:
			*o = South
		case West:
			*o = West
		default:
			return errors.New(fmt.Sprintf("%s is not a valid orientation", raw))
		}
	}
	return nil
}
Пример #3
0
// Generates required files
// Note: complex types are free form and can be aything
//       where simple types are top level only.
func generateRequiredFilesFrom(buildfile *BuildFile) ([]RequiredFile, error) {
	requiredFiles := []RequiredFile{}

	for _, file := range buildfile.Add.Simple {
		name := "Ansible " + file + " dir"
		requiredFiles = append(requiredFiles, RequiredFile{Name: name, FileName: file, FileType: "d" /*,RequiredFiles: AnsibleFiles*/})
	}

	// Treat Complex as fully qualified paths and as OS Files
	for _, file := range buildfile.Add.Complex {
		if file.Name == "" || file.Location == "" {
			msg := "Found empty values for " + Constants().buildFileName + " Complex entry. Check syntax, try again."
			Logger.Error(msg)
			return nil, errors.New(msg)
		}

		name := "file " + file.Name
		requiredFiles = append(requiredFiles, RequiredFile{Name: name, FileName: file.Location, FileType: "f"})
	}

	Logger.Trace(requiredFiles)

	return requiredFiles, nil
}