feat: check update

This commit is contained in:
2024-07-16 10:21:51 +08:00
parent 49da9100d2
commit b7d64cba7b
13 changed files with 693 additions and 4 deletions

View File

@@ -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
View 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
}