Skip to content

Commit

Permalink
feat: 优化静态资源目录
Browse files Browse the repository at this point in the history
  • Loading branch information
Licoy committed Sep 20, 2022
1 parent 43cace8 commit e24c529
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 199 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div align="center">
<h2>Fetch GitHub Hosts</h2>

![LOGO](logo.png)
![LOGO](assets/public/logo.png)

`fetch-github-hosts` 是主要为解决研究及学习人员访问 `Github` 过慢或其他问题而提供的 `Github Hosts` 同步工具

Expand All @@ -24,19 +24,19 @@
下载完成解压`tar.gz`压缩包,运行对应平台的执行文件即可运行( ⚠️ 注意:Linux下需要用`sudo`进行启动,Windows和MacOS会自动进行提权操作。)

#### 客户端模式
![client](./docs/client.png)
![client](assets/public/docs/client.png)

#### 客户端启动
![client-start](./docs/client-start.png)
![client-start](assets/public/docs/client-start.png)

#### 客户端hosts源选择
![client-select](./docs/client-select.png)
![client-select](assets/public/docs/client-select.png)

#### 客户端hosts源自定义
![client-custom](./docs/client-custom.png)
![client-custom](assets/public/docs/client-custom.png)

#### 服务端模式
![server](./docs/server.png)
![server](assets/public/docs/server.png)

### 命令行终端

Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
2 changes: 2 additions & 0 deletions assets/public/style.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
19 changes: 10 additions & 9 deletions fetch_hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package main

import (
"bytes"
"embed"
"encoding/json"
"fmt"
"github.com/h2non/filetype"
"io/ioutil"
"net"
"net/http"
Expand All @@ -19,12 +19,6 @@ const (
Darwin = "darwin"
)

//go:embed index.template
var indexTemplate embed.FS

//go:embed domains.json
var domainsJson embed.FS

func startClient(ticker *FetchTicker, url string, flog *fetchLog) {
flog.Print("远程hosts获取链接:" + url)
fn := func() {
Expand Down Expand Up @@ -99,6 +93,13 @@ func (s *serverHandle) ServeHTTP(resp http.ResponseWriter, request *http.Request
resp.Write(file)
return
}
if strings.HasPrefix(p, "/public/") {
file, _ := assetsFs.ReadFile("assets" + p)
kind, _ := filetype.Match(file)
resp.Header().Set("Content-Type", kind.MIME.Value)
resp.Write(file)
return
}
http.Redirect(resp, request, "/", http.StatusMovedPermanently)
}

Expand Down Expand Up @@ -168,7 +169,7 @@ func ServerFetchHosts() (err error) {
}

var templateFile []byte
templateFile, err = GetExecOrEmbedFile(&indexTemplate, "index.template")
templateFile, err = GetExecOrEmbedFile(&assetsFs, "assets/index.html")
if err != nil {
err = ComposeError("读取首页模板文件失败", err)
return
Expand Down Expand Up @@ -250,7 +251,7 @@ func getCleanGithubHosts() (hosts *bytes.Buffer, err error) {
}

func getGithubDomains() (domains []string, err error) {
fileData, err := GetExecOrEmbedFile(&domainsJson, "domains.json")
fileData, err := GetExecOrEmbedFile(&assetsFs, "assets/domains.json")
if err != nil {
err = ComposeError("读取文件domains.json错误", err)
return
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module github.com/Licoy/fetch-github-hosts
go 1.18

require (
fyne.io/fyne/v2 v2.2.1
fyne.io/fyne/v2 v2.2.2
github.com/getlantern/elevate v0.0.0-20210901195629-ce58359e4d0e
github.com/jessevdk/go-flags v1.5.0
github.com/spf13/viper v1.12.0
)

require (
fyne.io/systray v1.10.0 // indirect
fyne.io/systray v1.10.1-0.20220621085403-9a2652634e93 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
Expand All @@ -31,6 +31,7 @@ require (
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/h2non/filetype v1.1.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
github.com/magiconair/properties v1.8.6 // indirect
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
fyne.io/fyne/v2 v2.2.1 h1:yq8TgB2hrSjnRXcth07G9/+EcjvH7+o2YIK8rmMcIaI=
fyne.io/fyne/v2 v2.2.1/go.mod h1:drswO92dAguX9sHBuQWRaSAu7lp8BJBxPcXAarMW3rc=
fyne.io/systray v1.10.0 h1:Yr1D9Lxeiw3+vSuZWPlaHC8BMjIHZXJKkek706AfYQk=
fyne.io/systray v1.10.0/go.mod h1:oM2AQqGJ1AMo4nNqZFYU8xYygSBZkW2hmdJ7n4yjedE=
fyne.io/fyne/v2 v2.2.2 h1:/ox4o1JeDYb7LmcQS1LiJBmAnnsgKUEn25wZlAR8Ph0=
fyne.io/fyne/v2 v2.2.2/go.mod h1:MBoGuHzLLSXdQOWFAwWhIhYTEMp33zqtGCReSWhaQTA=
fyne.io/systray v1.10.1-0.20220621085403-9a2652634e93 h1:V2IC9t0Zj9Ur6qDbfhUuzVmIvXKFyxZXRJyigUvovs4=
fyne.io/systray v1.10.1-0.20220621085403-9a2652634e93/go.mod h1:oM2AQqGJ1AMo4nNqZFYU8xYygSBZkW2hmdJ7n4yjedE=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
Expand Down Expand Up @@ -196,6 +196,8 @@ github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfre
github.com/goxjs/gl v0.0.0-20210104184919-e3fafc6f8f2a/go.mod h1:dy/f2gjY09hwVfIyATps4G2ai7/hLwLkc5TrPqONuXY=
github.com/goxjs/glfw v0.0.0-20191126052801-d2efb5f20838/go.mod h1:oS8P8gVOT4ywTcjV6wZlOU4GuVFQ8F5328KY3MJ79CY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg=
github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY=
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down
9 changes: 1 addition & 8 deletions gui.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"embed"
"encoding/json"
"fmt"
"fyne.io/fyne/v2"
Expand All @@ -25,12 +24,6 @@ import (
var mainWindow fyne.Window
var fetchConf *FetchConf

//go:embed zcool-cryyt.ttf
var fyneFontEmbedFs embed.FS

//go:embed logo.png
var logoEmbedFs embed.FS

var _fileLog *fetchLog

func bootGui() {
Expand Down Expand Up @@ -90,7 +83,7 @@ func bootGui() {
}

func getLogoResource() fyne.Resource {
content, err := logoEmbedFs.ReadFile("logo.png")
content, err := assetsFs.ReadFile("assets/public/logo.png")
if err != nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion gui_theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type fghGuiTheme struct {
}

func (f *fghGuiTheme) Font(s fyne.TextStyle) fyne.Resource {
font, err := fyneFontEmbedFs.ReadFile(GuiFontName)
font, err := assetsFs.ReadFile("assets/zcool-cryyt.ttf")
if err != nil {
return theme.DefaultTheme().Font(s)
}
Expand Down

0 comments on commit e24c529

Please sign in to comment.