35 lines
772 B
Go
35 lines
772 B
Go
package model
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/dchest/siphash"
|
|
)
|
|
|
|
// compute the hash of a source code string
|
|
func HashSource(source string) uint64{
|
|
return siphash.Hash(0, 0, []byte(source))
|
|
}
|
|
|
|
// format a hash value as a hexidecimal string
|
|
func HashFormat(hash uint64) string{
|
|
return fmt.Sprintf("%016x", hash)
|
|
}
|
|
|
|
// parse a hexidecimal hash string
|
|
func HashParse(hash string) (uint64, error){
|
|
return strconv.ParseUint(hash, 16, 64)
|
|
}
|
|
|
|
type Script struct {
|
|
ID int64 `gorm:"primaryKey"`
|
|
Name string
|
|
Hash int64 // postgres does not support unsigned integers, so we have to pretend
|
|
Source string
|
|
SubmissionID int64 // which submission did this script first appear in
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|