Exemplo n.º 1
0
func (s *playersDB) Upload(userID int64, p api.Player, executable io.Reader) (*api.Player, error) {

	var buf bytes.Buffer
	io.Copy(&buf, executable)
	exeBytes := buf.Bytes()

	mh, err := multihash.Sum(exeBytes, multihash.SHA2_256)
	if err != nil {
		return nil, err
	}

	hashOfExe := mh.HexString()
	exePath := path.Join(s.FilestoragePath, hashOfExe)

	if err := ioutil.WriteFile(exePath, exeBytes, os.ModePerm); err != nil {
		return nil, err
	}

	if err := operator.Validate(exePath, s.Ports); err != nil {
		return nil, err
	}
	log.Printf("successfully validated %s", p)

	p.AuthorId = userID
	p.Path = hashOfExe
	if err := s.DB.Create(&p).Error; err != nil {
		return nil, err
	}
	return &p, nil
}
Exemplo n.º 2
0
func main() {
	flag.Parse()
	scheduler := operator.NewScheduler(14000, 100)
	fmt.Println(flag.Arg(0))
	err := operator.Validate(flag.Arg(0), scheduler)
	if err != nil {
		fmt.Println("Validation Failed!")
		fmt.Println(err)
	} else {
		fmt.Println("Validation succeeded")
	}
}