/
storage.go
62 lines (57 loc) · 1.43 KB
/
storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package gorgonzola
import (
"crypto/md5"
"fmt"
"io"
"net/http"
"time"
)
// Link contains Json-job link
type Link struct {
URL string
Created time.Time
Fetched time.Time
}
// Job contains single flattened job offer
type Job struct {
LinkKey string
Hash string
CompanyName string
CompanyURL string
CompanyRemoteFriendly bool
CompanyMarket string
CompanySize string
Position string
Title string
Description string
URL string
Type string
Posted string
Location string
Skills []string
SalaryRangeFrom int
SalaryRangeTo int
SalaryRangeCurrency string
EquityFrom float32
EquityTo float32
Perks []string
Apply string
Active bool
Created time.Time
}
// Storage interface to handle data persistence
type Storage interface {
AddURL(r *http.Request, url string) error
GetJobs(r *http.Request, limit int) ([]Job, error)
GetJob(r *http.Request, hash string) (*Job, error)
Update(r *http.Request) error
}
func (j *Job) getHash() string {
h := md5.New()
io.WriteString(h, j.CompanyName)
io.WriteString(h, j.Position)
io.WriteString(h, j.Title)
io.WriteString(h, j.URL)
io.WriteString(h, j.Posted)
return fmt.Sprintf("%x", h.Sum(nil))
}