Skip to content

Commit a5cd5cd

Browse files
committed
Use an embedded file system for the structure folder
1 parent 6c198a2 commit a5cd5cd

File tree

7 files changed

+16
-7
lines changed

7 files changed

+16
-7
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Download the most suitable build for your system from the `releases`. This will
4747

4848
```Shell
4949
sudo mkdir -p /var/www/ip-location-api
50-
sudo wget -q -O /var/www/ip-location-api/ip-location-api https://github.com/paul-norman/ip-location-api/releases/download/v1.0.0/ip-location-api-linux-x64.bin
50+
sudo wget -q -O /var/www/ip-location-api/ip-location-api https://github.com/paul-norman/ip-location-api/releases/latest/download/ip-location-api-linux-x64.bin
5151
sudo chmod +x /var/www/ip-location-api/ip-location-api
5252
```
5353

@@ -64,6 +64,8 @@ cd /var/www/ip-location-api
6464
sudo ./ip-location-api
6565
```
6666

67+
**It's probably a good idea to start the system up manually like this on the first run** because it will allow you to see the data loading progress / any problems. After that, using a service is a good idea.
68+
6769
## Configuration
6870

6971
Configuration is handled by an environmental (`.env`) file. Example files for each database type exist in the `.env.sample` directory. All database types share some information:

data_access.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package main
22

33
import (
4+
"embed"
45
"net"
56
"os"
67
)
78

9+
//go:embed structure/*.sql
10+
var dbStructures embed.FS
11+
812
func dbConnect() {
913
switch os.Getenv("DB_TYPE") {
1014
case "postgres": postgresConnect()

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
2424
github.com/seancfoley/bintree v1.3.1 // indirect
2525
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
26-
golang.org/x/sys v0.22.0 // indirect
26+
golang.org/x/sys v0.23.0 // indirect
2727
modernc.org/libc v1.56.0 // indirect
2828
modernc.org/mathutil v1.6.0 // indirect
2929
modernc.org/memory v1.8.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
4545
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
4646
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
4747
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
48-
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
49-
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
48+
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
49+
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
5050
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
5151
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
5252
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

mysql.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ func mysqlSaveCities(cities []IpCity) {
259259
}
260260

261261
func mysqlFile(sqlPath string) {
262-
sqlBytes, err := os.ReadFile(sqlPath)
262+
sqlBytes, err := dbStructures.ReadFile(sqlPath)
263+
//sqlBytes, err := os.ReadFile(sqlPath)
263264
if err != nil {
264265
panic(err)
265266
}

postgres.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ func fixPostgresVars(sqlString string) string {
315315
}
316316

317317
func postgresFile(sqlPath string) {
318-
sqlBytes, err := os.ReadFile(sqlPath)
318+
sqlBytes, err := dbStructures.ReadFile(sqlPath)
319+
//sqlBytes, err := os.ReadFile(sqlPath)
319320
if err != nil {
320321
panic(err)
321322
}

sqlite.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ func sqliteSaveCities(cities []IpCity) {
351351
}
352352

353353
func sqliteFile(sqlPath string) {
354-
sqlBytes, err := os.ReadFile(sqlPath)
354+
sqlBytes, err := dbStructures.ReadFile(sqlPath)
355+
//sqlBytes, err := os.ReadFile(sqlPath)
355356
if err != nil {
356357
panic(err)
357358
}

0 commit comments

Comments
 (0)