feat: check update
This commit is contained in:
@@ -39,6 +39,17 @@ func (helper *SQLiteHelper) Close() {
|
||||
helper.db.Close()
|
||||
}
|
||||
|
||||
func (helper *SQLiteHelper) ReloadDatabase() bool {
|
||||
helper.db.Close()
|
||||
db, err := sql.Open("sqlite3", helper.connectionString)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return false
|
||||
}
|
||||
helper.db = db
|
||||
return true
|
||||
}
|
||||
|
||||
func (helper *SQLiteHelper) QueryMacAddressByPrefix(prefix string) (*MacAddress, error) {
|
||||
const tableName = "MacAddresses"
|
||||
query := fmt.Sprintf("SELECT * FROM %s WHERE Prefix = ?", tableName)
|
||||
|
||||
28
service/update.go
Normal file
28
service/update.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type UpdateService struct {
|
||||
Url string
|
||||
}
|
||||
|
||||
func NewUpdateService(url string) *UpdateService {
|
||||
return &UpdateService{Url: url}
|
||||
}
|
||||
|
||||
func (updater *UpdateService) GetLatestVersion() *string {
|
||||
res, err := http.Get(updater.Url)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
defer res.Body.Close()
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
str := string(body)
|
||||
return &str
|
||||
}
|
||||
Reference in New Issue
Block a user