Skip to content

Commit f6384c8

Browse files
committed
完善文档
1 parent 12486b9 commit f6384c8

File tree

11 files changed

+202
-51
lines changed

11 files changed

+202
-51
lines changed

README.md

+96-39
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,119 @@
11
studygolang
22
===========
3-
[Golang中文社区 | Go语言学习园地](http://studygolang.com "Golang中文社区 | Go语言学习园地") 源码
3+
[Go语言中文网 | Golang中文社区 | Go语言学习园地](http://studygolang.com "Go语言中文网 | Golang中文社区 | Go语言学习园地") 源码
44

55
网站上线时间:2013-03-15 14:38:09
66

7-
目前只开发了主要功能,还有不少功能在不断开发中。欢迎有兴趣的gopher们参与进来,一起构建一个完善的 Golang 中文社区,Go语言爱好者的学习家园。
7+
目前开发了大部分功能,还有不少功能在不断开发完善中。欢迎有兴趣的 gopher 们参与进来,一起构建一个完善的 Go 语言中文网,Go语言爱好者的学习家园。
88

9-
#目前在正开发或需要开发的功能
9+
#目前需要开发的功能
1010
1. 小贴士
11-
2. 收藏
12-
3. 关注
13-
4. 用第三方账号登录
14-
5. 绑定github后显示其代码
15-
6. 同步到微博?
16-
7. 博文评论 @用户 待完善
17-
18-
# 本地搭建一个 Golang 社区 #
19-
20-
1、下载 studygolang 代码
11+
2. 关注
12+
3. 用第三方账号登录
13+
4. 绑定 github 后显示其代码
14+
5. 评论直接支持内嵌wide
15+
6. 评论支持编辑、删除自己的评论
16+
7. 代码片段分享
17+
8. rss 订阅
18+
9. ...
19+
20+
# 本地搭建一个 Go语言中文网 #
21+
22+
## 步骤一
23+
24+
首先你都需要下载代码,因为代码中有很多静态资源。可以[点击这里下载](https://github.com/studygolang/studygolang/archive/master.zip)`git clone https://github.com/studygolang/studygolang` 下载。
25+
26+
## 步骤二
27+
28+
### 方式一:二进制安装
29+
30+
1、下载预编译好的二进制文件(将下载的文件放入源码的bin目录下,自己创建好bin目录)
31+
32+
<table class="table table-bordered table-striped table-condensed">
33+
<tr>
34+
<th>操作系统</th>
35+
<th>架构</th>
36+
<th>下载链接</th>
37+
<th>MD5SUM</th>
38+
</tr>
39+
<tr>
40+
<td>Linux</td>
41+
<td>amd64</td>
42+
<td><a href="http://pan.baidu.com/s/1i52MPUX#path=%252Fshare%252Fstudygolang%252F2.0%252Flinux" target="_blank">下载地址</a></td>
43+
<td>2f24752d2b382b218c50b8f64fb3ad2e</td>
44+
</tr>
45+
<tr>
46+
<td>OS X</td>
47+
<td>amd64</td>
48+
<td><a href="http://pan.baidu.com/s/1i52MPUX#path=%252Fshare%252Fstudygolang%252F2.0%252Fdarwin" target="_blank">下载地址</a></td>
49+
<td>2adab465eceab2ff89d23c21ffaafcaf</td>
50+
</tr>
51+
<tr>
52+
<td>Windows</td>
53+
<td>amd64</td>
54+
<td><a href="http://pan.baidu.com/s/1i52MPUX#path=%252Fshare%252Fstudygolang%252F2.0%252Fwindows%252Famd64" target="_blank">下载地址</a></td>
55+
<td>9d261afb56c3989fe67238fe8a09abf8</td>
56+
</tr>
57+
<tr>
58+
<td>Windows</td>
59+
<td>386</td>
60+
<td><a href="http://pan.baidu.com/s/1i52MPUX#path=%252Fshare%252Fstudygolang%252F2.0%252Fwindows%252F386" target="_blank">下载地址</a></td>
61+
<td>1723fbc4f2c841e1f45b303df8a0dc0f</td>
62+
</tr>
63+
</table>
64+
65+
### 方式二:源码安装
66+
67+
要求 Go 1.6+
68+
69+
1、下载 gvt 依赖管理工具
2170

22-
git clone https://github.com/studygolang/studygolang
71+
go get github.com/polaris1119/gvt
72+
73+
下载后将 gvt 加入 PATH 中。
74+
75+
2、下载安装依赖
2376

24-
2、下载安装依赖库(如果依赖库下载不下来可以联系我)
77+
cd 到 studygolang 源码目录
2578

26-
cd studygolang/websites/code/thirdparty
27-
// windows 下执行
79+
// unix
80+
./getpkg.sh
81+
// windows
2882
getpkg.bat
29-
// linux/mac 下执行
30-
sh getpkg
3183

32-
3、编译并运行 studygolang
84+
3、编译 studygolang
85+
86+
// unix
87+
./install.sh
88+
// windows
89+
install.bat
3390

34-
先编译
91+
这样便编译好了 studygolang
3592

36-
// 接着上一步
37-
cd ../studygolang/
38-
// windows 下执行
39-
install.bat
40-
// linux/mac 下执行
41-
sh install
42-
43-
这样便编译好了 studygolang,下面运行 studygolang。(运行前可以根据需要修改 config/config.json.example 配置,当然首先得改名为 config.json)
93+
## 步骤三
94+
95+
在 studygolang 源码中的 bin 目录下应该有了 studygolang 可执行文件。
4496

45-
// windows 下执行
97+
接下来启动 studygolang。
98+
99+
// unix
100+
./start.sh
101+
// windows
46102
start.bat
47-
// linux/mac 下执行
48-
sh start
103+
104+
或者
105+
106+
// unix
107+
bin/studygolang
108+
// windows
109+
bin\studygolang.exe
49110

50111
一切顺利的话,studygolang 应该就启动了。
51112

52-
4、浏览器中查看
113+
## 步骤四
53114

54-
在浏览器中输入:http://127.0.0.1:8080
115+
在浏览器中输入:http://127.0.0.1:8088
55116

56117
应该就能看到了。
57118

58-
5、建立数据库
59-
60-
运行起来了,但没有建数据库。源码中有一个 databases 文件夹,里面有建表和初始化的sql语句。之前这些sql之前,在mysql数据库中建立一个数据库:studygolang,之后执行这些sql语句。
61-
62-
根据你的数据库设置,修改上面提到的 `config/config.json` 对应的配置,重新启动 studygolang.(通过restart脚本重新启动)
119+
接下来你会看到图形化安装界面,一步步照做吧。

src/http/controller/install.go

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Copyright 2016 The StudyGolang Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
// http://studygolang.com
5+
// Author: polaris [email protected]
6+
17
package controller
28

39
import (
@@ -9,9 +15,8 @@ import (
915
"model"
1016
"net/http"
1117
"net/url"
12-
"os"
18+
"runtime"
1319
"strconv"
14-
"syscall"
1520

1621
"github.com/labstack/echo"
1722
"github.com/polaris1119/config"
@@ -62,7 +67,7 @@ func (self InstallController) SetupConfig(ctx echo.Context) error {
6267
}
6368

6469
// DoInstall 执行安装,包括站点简单配置,安装数据库(创建数据库、表,填充基本数据)等
65-
func (InstallController) DoInstall(ctx echo.Context) error {
70+
func (self InstallController) DoInstall(ctx echo.Context) error {
6671
if db.MasterDB == nil {
6772
return ctx.Redirect(http.StatusSeeOther, "/install")
6873
}
@@ -132,9 +137,10 @@ func (InstallController) DoInstall(ctx echo.Context) error {
132137

133138
data["step"] = 3
134139

135-
go func() {
136-
syscall.Kill(os.Getpid(), syscall.SIGUSR2)
137-
}()
140+
data["os"] = runtime.GOOS
141+
142+
// 为了保证程序正常,需要重启
143+
go self.reload()
138144
}
139145
return renderInstall(ctx, "install/install.html", data)
140146
}

src/http/controller/install_unix.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The StudyGolang Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
// http://studygolang.com
5+
// Author: polaris [email protected]
6+
7+
// +build !windows,!plan9
8+
9+
package controller
10+
11+
import (
12+
"os"
13+
"syscall"
14+
)
15+
16+
func (InstallController) reload() {
17+
syscall.Kill(os.Getpid(), syscall.SIGUSR2)
18+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2016 The StudyGolang Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
// http://studygolang.com
5+
// Author: polaris [email protected]
6+
7+
package controller
8+
9+
func (InstallController) reload() {
10+
}

src/logic/article.go

+10
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ func (ArticleLogic) ParseArticle(ctx context.Context, articleUrl string, auto bo
127127
title = strings.TrimSpace(replacer.Replace(title))
128128

129129
contentSelection := doc.Find(rule.Content)
130+
131+
// relative url -> abs url
132+
contentSelection.Find("img").Each(func(i int, s *goquery.Selection) {
133+
if v, ok := s.Attr("src"); ok {
134+
if !strings.HasPrefix(v, "http") {
135+
s.SetAttr("src", domain+v)
136+
}
137+
}
138+
})
139+
130140
content, err := contentSelection.Html()
131141
if err != nil {
132142
logger.Errorln("goquery parse content error:", err)

src/logic/user.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ func (self UserLogic) CreateUser(ctx context.Context, form url.Values) (errMsg s
8282
// 随机给一个默认头像
8383
user.Avatar = DefaultAvatars[rand.Intn(len(DefaultAvatars))]
8484
user.Open = 1
85-
// 避免前端伪造,传递 status=1
86-
user.Status = model.UserStatusNoAudit
85+
86+
if !user.IsRoot {
87+
// 避免前端伪造,传递 status=1
88+
user.Status = model.UserStatusNoAudit
89+
}
8790
_, err = session.Insert(user)
8891
if err != nil {
8992
session.Rollback()
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// +build !windows,!plan9
2+
3+
package main
4+
5+
import (
6+
"log"
7+
8+
"github.com/facebookgo/grace/gracehttp"
9+
"github.com/labstack/echo/engine/standard"
10+
)
11+
12+
func gracefulRun(std *standard.Server) {
13+
log.Fatal(gracehttp.Serve(std.Server))
14+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"time"
6+
7+
"github.com/labstack/echo/engine/standard"
8+
"github.com/tylerb/graceful"
9+
)
10+
11+
func gracefulRun(std *standard.Server) {
12+
log.Fatal(graceful.ListenAndServe(std.Server, 5*time.Second))
13+
}

src/server/studygolang/main.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"http/controller"
1212
"http/controller/admin"
1313
"io/ioutil"
14-
"log"
1514
"math/rand"
1615
"os"
1716
"path/filepath"
@@ -22,7 +21,6 @@ import (
2221

2322
pwm "http/middleware"
2423

25-
"github.com/facebookgo/grace/gracehttp"
2624
"github.com/fatih/structs"
2725
"github.com/labstack/echo"
2826
"github.com/labstack/echo/engine/standard"
@@ -68,7 +66,7 @@ func main() {
6866
std := standard.New(getAddr())
6967
std.SetHandler(e)
7068

71-
log.Fatal(gracehttp.Serve(std.Server))
69+
gracefulRun(std)
7270
}
7371

7472
func getAddr() string {

src/vendor/manifest

+20-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
"revision": "3ad29d1ad1c4f2023e355603324348cf1f4b2d48",
2020
"branch": "master"
2121
},
22+
{
23+
"importpath": "github.com/codegangsta/negroni",
24+
"repository": "https://github.com/codegangsta/negroni",
25+
"revision": "feacfc52d357c844f524c794947493483ed881b3",
26+
"branch": "master"
27+
},
2228
{
2329
"importpath": "github.com/davecgh/go-spew/spew",
2430
"repository": "https://github.com/davecgh/go-spew",
@@ -251,7 +257,7 @@
251257
{
252258
"importpath": "github.com/polaris1119/config",
253259
"repository": "https://github.com/polaris1119/config",
254-
"revision": "0653707cf2ad9116ef0dbffa545dafa29c505866",
260+
"revision": "06a751e884f30c6ca264fd45bb158e154fa865e4",
255261
"branch": "master"
256262
},
257263
{
@@ -345,6 +351,12 @@
345351
"revision": "89173bcdda19db0eb88aef1e1cb1cb2505561d31",
346352
"branch": "master"
347353
},
354+
{
355+
"importpath": "github.com/tylerb/graceful",
356+
"repository": "https://github.com/tylerb/graceful",
357+
"revision": "84177357ab104029f9237abcb52339a7b80760ef",
358+
"branch": "master"
359+
},
348360
{
349361
"importpath": "github.com/valyala/fasthttp",
350362
"repository": "https://github.com/valyala/fasthttp",
@@ -371,6 +383,13 @@
371383
"branch": "master",
372384
"path": "/html"
373385
},
386+
{
387+
"importpath": "golang.org/x/net/netutil",
388+
"repository": "https://github.com/golang/net",
389+
"revision": "313cf39d4ac368181bce6960ac9be9e7cee67e68",
390+
"branch": "master",
391+
"path": "/netutil"
392+
},
374393
{
375394
"importpath": "golang.org/x/net/websocket",
376395
"repository": "https://github.com/golang/net",

template/install/install.html

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ <h1 id="logo"><img alt="WordPress" src="/static/img/logo1.png" /></h1>
1111
<h1>成功!</h1>
1212

1313
<p>Go语言中文网 安装完成。您是否还沉浸在愉悦的安装过程中?很遗憾,一切皆已完成! :)</p>
14+
{{if eq .os "windows"}}
15+
<p>您当前是Windows,需要手动重启本程序,以便程序正常!</p>
16+
{{endif}}
1417

1518
<table class="form-table install-success">
1619
<tr>

0 commit comments

Comments
 (0)