forked from wangyiwy/oktools
-
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.
- Loading branch information
0 parents
commit 23e9cb3
Showing
59 changed files
with
5,662 additions
and
0 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,5 @@ | ||
.idea/ | ||
*.exe | ||
*.log | ||
build/ | ||
conf.yaml |
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,23 @@ | ||
app: | ||
mode: debug | ||
log-file: oktools.log | ||
|
||
http: | ||
port: 80 | ||
ssl: | ||
enable: false | ||
crt: | ||
key: | ||
|
||
database: | ||
host: 127.0.0.1 | ||
port: 5432 | ||
username: | ||
password: | ||
dbname: | ||
|
||
third-party: | ||
amap: | ||
key: | ||
serverchan: | ||
key: |
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,12 @@ | ||
module oktools | ||
|
||
go 1.12 | ||
|
||
require ( | ||
github.com/gin-gonic/gin v1.4.0 | ||
github.com/jinzhu/gorm v1.9.10 | ||
github.com/tdewolff/minify v2.3.6+incompatible | ||
github.com/tdewolff/minify/v2 v2.5.0 | ||
github.com/tdewolff/parse v2.3.4+incompatible // indirect | ||
gopkg.in/yaml.v2 v2.2.2 | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
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,197 @@ | ||
package main | ||
|
||
import ( | ||
"archive/tar" | ||
"compress/gzip" | ||
"fmt" | ||
"github.com/tdewolff/minify/v2" | ||
"github.com/tdewolff/minify/v2/css" | ||
"github.com/tdewolff/minify/v2/html" | ||
"github.com/tdewolff/minify/v2/js" | ||
"io" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
const buildDir = "./build" | ||
const tempDir = buildDir + "/oktools" | ||
|
||
const srcTplDir = "./tpl" | ||
const dstTplDir = tempDir + "/tpl/" | ||
|
||
const srcCSSDir = "./static/css" | ||
const dstCSSDir = tempDir + "/static/css/" | ||
|
||
const srcJSDir = "./static/js" | ||
const dstJSDir = tempDir + "/static/js/" | ||
|
||
func main() { | ||
clean() | ||
buildGo() | ||
minifyStatic() | ||
copyFiles() | ||
packAll() | ||
} | ||
|
||
func clean() { | ||
err := os.RemoveAll(buildDir) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
} | ||
|
||
func buildGo() { | ||
err := os.Setenv("GOOS", "linux") | ||
err = os.Setenv("GOARCH", "amd64") | ||
checkError(err) | ||
|
||
cmd := exec.Command("go", "build", "-o", tempDir+"/oktools", "-i", "./src") | ||
cmd.Stderr = os.Stderr | ||
out, err := cmd.Output() | ||
checkError(err) | ||
fmt.Println(string(out)) | ||
} | ||
|
||
func minifyStatic() { | ||
m := minify.New() | ||
m.AddFunc("text/css", css.Minify) | ||
m.AddFunc("text/html", html.Minify) | ||
m.AddFuncRegexp(regexp.MustCompile("^(application|text)/(x-)?(java|ecma)script$"), js.Minify) | ||
|
||
minifyFiles(m, "text/html", srcTplDir, dstTplDir) | ||
minifyFiles(m, "text/css", srcCSSDir, dstCSSDir) | ||
minifyFiles(m, "application/javascript", srcJSDir, dstJSDir) | ||
} | ||
|
||
func copyFiles() { | ||
copyDir("./sql", tempDir+"/sql") | ||
copyFile("./static/favicon.ico", tempDir+"/static/favicon.ico") | ||
copyFile("./conf.yaml", tempDir+"/conf.yaml") | ||
} | ||
|
||
func minifyFiles(m *minify.M, mimeType, src, dst string) { | ||
err := os.MkdirAll(dst, os.ModePerm) | ||
checkError(err) | ||
|
||
err = filepath.Walk(src, func(path string, info os.FileInfo, err error) error { | ||
if info.IsDir() { | ||
return nil | ||
} | ||
|
||
file, err := os.Open(path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
dest, err := os.Create(dst + info.Name()) | ||
if err != nil { | ||
return err | ||
} | ||
defer dest.Close() | ||
|
||
if strings.HasSuffix(info.Name(), "min.css") || strings.HasSuffix(info.Name(), "min.js") { | ||
_, err = io.Copy(dest, file) | ||
return err | ||
} | ||
|
||
return m.Minify(mimeType, dest, file) | ||
}) | ||
checkError(err) | ||
} | ||
|
||
func copyDir(src string, dst string) { | ||
err := os.MkdirAll(dst, os.ModePerm) | ||
checkError(err) | ||
|
||
dir, _ := os.Open(src) | ||
defer dir.Close() | ||
objects, err := dir.Readdir(-1) | ||
|
||
for _, obj := range objects { | ||
srcFile := src + "/" + obj.Name() | ||
dstFile := dst + "/" + obj.Name() | ||
|
||
if obj.IsDir() { | ||
copyDir(srcFile, dstFile) | ||
} else { | ||
copyFile(srcFile, dstFile) | ||
} | ||
} | ||
} | ||
|
||
func copyFile(src string, dst string) { | ||
srcFile, err := os.Open(src) | ||
defer srcFile.Close() | ||
checkError(err) | ||
|
||
destFile, err := os.Create(dst) | ||
defer destFile.Close() | ||
checkError(err) | ||
|
||
_, err = io.Copy(destFile, srcFile) | ||
checkError(err) | ||
|
||
err = os.Chmod(dst, os.ModePerm) | ||
checkError(err) | ||
} | ||
|
||
func packAll() { | ||
dir, err := os.Open(tempDir) | ||
defer dir.Close() | ||
checkError(err) | ||
|
||
info, err := dir.Stat() | ||
checkError(err) | ||
|
||
d, err := os.Create(buildDir + "/" + info.Name() + ".tar.gz") | ||
defer d.Close() | ||
checkError(err) | ||
|
||
gw := gzip.NewWriter(d) | ||
defer gw.Close() | ||
|
||
tw := tar.NewWriter(gw) | ||
defer tw.Close() | ||
|
||
compress(dir, "", tw) | ||
} | ||
|
||
func compress(file *os.File, prefix string, tw *tar.Writer) { | ||
info, err := file.Stat() | ||
checkError(err) | ||
|
||
if info.IsDir() { | ||
prefix = prefix + "/" + info.Name() | ||
fileInfos, err := file.Readdir(-1) | ||
checkError(err) | ||
|
||
for _, fi := range fileInfos { | ||
f, err := os.Open(file.Name() + "/" + fi.Name()) | ||
checkError(err) | ||
|
||
compress(f, prefix, tw) | ||
f.Close() | ||
} | ||
} else { | ||
h, err := tar.FileInfoHeader(info, "") | ||
checkError(err) | ||
|
||
h.Name = prefix + "/" + h.Name | ||
h.Mode = int64(info.Mode().Perm()) | ||
err = tw.WriteHeader(h) | ||
checkError(err) | ||
|
||
_, err = io.Copy(tw, file) | ||
err = file.Close() | ||
checkError(err) | ||
} | ||
} | ||
|
||
func checkError(err error) { | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
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,64 @@ | ||
/* | ||
Navicat Premium Data Transfer | ||
Source Server : pgsql-localhost | ||
Source Server Type : PostgreSQL | ||
Source Server Version : 110002 | ||
Source Host : localhost:5432 | ||
Source Catalog : oktools | ||
Source Schema : public | ||
Target Server Type : PostgreSQL | ||
Target Server Version : 110002 | ||
File Encoding : 65001 | ||
Date: 24/09/2019 12:51:40 | ||
*/ | ||
|
||
|
||
-- ---------------------------- | ||
-- Table structure for tools | ||
-- ---------------------------- | ||
DROP TABLE IF EXISTS "public"."tools"; | ||
CREATE TABLE "public"."tools" ( | ||
"path" varchar(255) COLLATE "pg_catalog"."default" NOT NULL, | ||
"title" varchar(255) COLLATE "pg_catalog"."default" NOT NULL, | ||
"icon" varchar(255) COLLATE "pg_catalog"."default", | ||
"category" int2 NOT NULL DEFAULT 0, | ||
"usage_count" int4 NOT NULL DEFAULT 0 | ||
) | ||
; | ||
|
||
-- ---------------------------- | ||
-- Records of tools | ||
-- ---------------------------- | ||
INSERT INTO "public"."tools" VALUES ('/json2yaml', 'JSON/YAML转换', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/json2go', 'JSON转Go Struct', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/unicode', 'Unicode编码转换', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/url', 'URL编码解码', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/hash', 'Hash计算', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/morse', '摩斯电码', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/number', '进制转换', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/websocket', 'WebSocket测试', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/timestamp', 'Unix时间戳', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/regex', '正则表达式测试', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/qrcode', '二维码制作', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/ip', 'IP地址信息', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/file-hash', '文件Hash计算', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/rsa', 'RSA加密解密', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/des', 'DES加密解密', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/aes', 'AES加密解密', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/color', '颜色值转换', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/image2base64', '图片Base64编码', '', 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/base64', 'Base64编码解码', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/json', 'JSON格式化', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/placeholder', 'SVG占位图', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/tinyimg', '图片压缩', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/json2xml', 'JSON/XML转换', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/clocks', 'CSS时钟', NULL, 0, 0); | ||
INSERT INTO "public"."tools" VALUES ('/pdf2img', 'PDF转图片', NULL, 0, 0); | ||
|
||
-- ---------------------------- | ||
-- Primary Key structure for table tools | ||
-- ---------------------------- | ||
ALTER TABLE "public"."tools" ADD CONSTRAINT "tools_pkey" PRIMARY KEY ("path"); |
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,59 @@ | ||
package conf | ||
|
||
import ( | ||
"gopkg.in/yaml.v2" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
type Config struct { | ||
App struct { | ||
Mode string `yaml:"mode"` | ||
LogFile string `yaml:"log-file"` | ||
} `yaml:"app"` | ||
Http struct { | ||
Port string `yaml:"port"` | ||
SSL struct { | ||
Enable bool `yaml:"enable"` | ||
Crt string `yaml:"crt"` | ||
Key string `yaml:"key"` | ||
} `yaml:"ssl"` | ||
} `yaml:"http"` | ||
DataBase struct { | ||
Host string `yaml:"host"` | ||
Port string `yaml:"port"` | ||
Username string `yaml:"username"` | ||
Password string `yaml:"password"` | ||
DbName string `yaml:"dbname"` | ||
} `yaml:"database"` | ||
ThirdParty struct { | ||
Amap struct { | ||
Key string `yaml:"key"` | ||
} `yaml:"amap"` | ||
ServerChan struct { | ||
Key string `yaml:"key"` | ||
} `yaml:"serverchan"` | ||
} `yaml:"third-party"` | ||
} | ||
|
||
var Conf = &Config{} | ||
|
||
func init() { | ||
var conf string | ||
if len(os.Args) == 2 { | ||
conf = os.Args[1] | ||
} | ||
if conf == "" { | ||
conf = "conf.yaml" | ||
} | ||
|
||
data, err := ioutil.ReadFile(conf) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = yaml.UnmarshalStrict(data, &Conf) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
Oops, something went wrong.