forked from mpolden/echoip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- [x] Pipeline to update binary on server when changes are pushed - [x] Added config option for Cache TTL in Seconds in `/etc/echoip/config.toml - [x] Updated Readme for Cache Options - [x] Added `Null` cache for optional no use of cache - [x] Adding Redis Cache - [x] Moving configuration to file config - [x] Automatic Release for amd64 linux - [x] Adding automatic deployment - Added `LICENSE` file to the release file
- Loading branch information
Showing
19 changed files
with
585 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- "*" | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: "1.18.x" | ||
|
||
- name: Build EchoIP binary | ||
run: go build -o ./echoip ./cmd/echoip/main.go | ||
|
||
- name: Upload Release Artifact | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
zip -r echoip-linux-amd64-${{ github.ref_name }}.zip echoip html LICENSE | ||
- name: Create Release | ||
uses: ncipollo/release-action@v1 | ||
with: | ||
artifacts: echoip-linux-amd64-${{ github.ref_name }}.zip | ||
bodyFile: "CHANGELOG.md" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Changelog | ||
|
||
## 1.0.0 (2023-10-06) | ||
|
||
|
||
### Features | ||
|
||
* Adding test to main.go ([a4d13ad](https://github.com/levelsoftware/echoip/commit/a4d13ad0edcc3c9dd591ad1aa26d2b50b8528168)) | ||
* Remove if inside loop from String() ([08fdacc](https://github.com/levelsoftware/echoip/commit/08fdacc08254a53169a19ff7f14cfad4c70655c1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package cache | ||
|
||
import ( | ||
"context" | ||
|
||
parser "github.com/levelsoftware/echoip/iputil/paser" | ||
) | ||
|
||
type CachedResponse struct { | ||
response *parser.Response | ||
} | ||
|
||
func (cr *CachedResponse) Build(response parser.Response) CachedResponse { | ||
return CachedResponse{ | ||
response: &response, | ||
} | ||
} | ||
|
||
func (cr *CachedResponse) Get() parser.Response { | ||
return *cr.response | ||
} | ||
|
||
func (cr *CachedResponse) IsSet() bool { | ||
return cr.response != nil | ||
} | ||
|
||
type Cache interface { | ||
Get(ctx context.Context, ip string, cachedResponse *CachedResponse) error | ||
Set(ctx context.Context, ip string, response CachedResponse, cacheTtl int) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cache | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type Null struct{} | ||
|
||
func (nc *Null) Get(ctx context.Context, ip string, cachedResponse *CachedResponse) error { | ||
return nil | ||
} | ||
|
||
func (nc *Null) Set(ctx context.Context, ip string, response CachedResponse, cacheTtl int) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cache | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/go-redis/cache/v9" | ||
"github.com/redis/go-redis/v9" | ||
) | ||
|
||
type Redis struct { | ||
cache *cache.Cache | ||
} | ||
|
||
func RedisCache(url string) (Redis, error) { | ||
opts, err := redis.ParseURL(url) | ||
if err != nil { | ||
return Redis{}, err | ||
} | ||
rdb := redis.NewClient(opts) | ||
cache := cache.New(&cache.Options{ | ||
Redis: rdb, | ||
LocalCache: cache.NewTinyLFU(1000, time.Minute), | ||
}) | ||
return Redis{ | ||
cache: cache, | ||
}, nil | ||
} | ||
|
||
func (r *Redis) Get(ctx context.Context, ip string, cachedResponse *CachedResponse) error { | ||
return r.cache.Get(ctx, ip, cachedResponse) | ||
} | ||
|
||
func (r *Redis) Set(ctx context.Context, ip string, response CachedResponse, cacheTtl int) error { | ||
return r.cache.Set(&cache.Item{ | ||
Ctx: ctx, | ||
Key: ip, | ||
Value: response, | ||
TTL: time.Duration(cacheTtl * int(time.Second)), | ||
}) | ||
} |
Oops, something went wrong.