Skip to content

Commit

Permalink
fix dir crate
Browse files Browse the repository at this point in the history
  • Loading branch information
penndev committed Nov 26, 2023
1 parent 66080c2 commit 0a8a66e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 18 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MODE=prod
KEY=123456
LISTEN=:8888
NGINX_PATH=/usr/bin/nginx
CACHE_DIR=/data
CACHE_TASK_CYCLE=60
CACHE_DISK_LIMIT=90
Expand Down
15 changes: 8 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,33 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.21.x']
steps:
- name: Setup Go ${{ matrix.go-version }}
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
go-version: '1.21.x'
- name: Setup Luajit
run: |
sudo apt-get update
sudo apt-get install -y luajit
- name: Checkout Code
uses: actions/checkout@v4
- name: Build Golnag
run: go build
run: |
go version
export CGO_ENABLED=0
go build
- name: Build Luajit
run: |
luajit -v
folder="./script"
for file in $folder/*.lua
do
luajit -b $file $file
done
- name: Archive Files
run: |
tar -czvf wafcdn.tar.gz *
tar -czvf wafcdn.tar.gz wafcdn .env.sample conf script
zip -r wafcdn.zip *
- name: Release
uses: softprops/action-gh-release@v1
Expand Down
1 change: 0 additions & 1 deletion conf/nginx.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ env UPCACHE_LIMIT_COUNT=10;

http {
access_log off;

resolver 223.5.5.5 223.6.6.6 valid=300s;
lua_package_path "$prefix/script/?.lua;;";
lua_shared_dict ssl 128m;
Expand Down
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
func main() {
conf.LoadEnv(".env") // 加载与校验配置
conf.LoadDomain(conf.DomainFileName) // 加载持久域名配置信息
orm.LoadCache(".cache.db") // 加载持久缓存sqlite数据。
orm.CacheInAndLruOutTask() // 启动缓存文件入库和清理。
util.StartNginx() // 启动nginx(openresty)
util.InitNetTraffic() // 监控系统的流量
serve.Listen() // http接口
util.MkdirLogDir("logs")
orm.LoadCache(".cache.db") // 加载持久缓存sqlite数据。
orm.CacheInAndLruOutTask() // 启动缓存文件入库和清理。
util.StartNginx() // 启动nginx(openresty)
util.InitNetTraffic() // 监控系统的流量
serve.Listen() // http接口
}
11 changes: 8 additions & 3 deletions serve/conf/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package conf
import (
"crypto/md5"
"encoding/json"
"fmt"
"io"
"os"
"time"
)
Expand Down Expand Up @@ -78,14 +80,17 @@ func GetDomain() map[string]DomainItem {
var DomainFileName = ".domain.json"

func LoadDomain(domainFile string) {
domainByte, err := os.ReadFile(domainFile)
domainRead, err := os.OpenFile(domainFile, os.O_RDWR|os.O_CREATE, 0755)
if err != nil {
panic(err)
}
domainByte, err := io.ReadAll(domainRead)
if err != nil {
panic(err)
}
// 如果文件不存在怎么办。?待思考
var domainConfigs []DomainItem
if err := json.Unmarshal(domainByte, &domainConfigs); err != nil {
panic(err)
fmt.Println(err)
}
domainMap = make(map[string]DomainItem)
for _, domaininfo := range domainConfigs {
Expand Down
1 change: 0 additions & 1 deletion serve/conf/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,4 @@ func LoadEnv(f string) {
}
DocacheLimitStart = docacheLimitStart
DocacheLimitCount = docacheLimitCount

}
6 changes: 5 additions & 1 deletion serve/util/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ func genNginxConfFile() {
}

func StartNginx() {
// 获取nginx的安装路径。
nginxPath := os.Getenv("NGINX_PATH")
if nginxPath == "" {
panic("cant find the NGINX_PATH")
}
// 生成nginx配置文件。
genNginxConfFile()

var err error
var cmd *exec.Cmd
_, err = os.Stat("logs/nginx.pid")
Expand Down
14 changes: 14 additions & 0 deletions serve/util/util.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package util

import (
"fmt"
"log"
"os"
"time"

"github.com/penndev/wafcdn/serve/conf"
Expand Down Expand Up @@ -47,3 +49,15 @@ func InitNetTraffic() {
}
}()
}

func MkdirLogDir(logDir string) {
if _, err := os.Stat(logDir); os.IsNotExist(err) {
err := os.MkdirAll(logDir, 0755)
if err != nil {
panic(err)
}
fmt.Println("Directory created successfully")
} else if err != nil {
panic(err)
}
}

0 comments on commit 0a8a66e

Please sign in to comment.