├── src
├── utils
│ ├── file.go
│ ├── init.go
│ ├── errors.go
│ ├── config.go
│ ├── redis.go
│ ├── code.go
│ └── mysql.go
├── domain
│ ├── init.go
│ ├── linkcat.go
│ ├── account.go
│ ├── articles.go
│ ├── links.go
│ └── cuslinks.go
├── controller
│ ├── linkcat.go
│ ├── account.go
│ ├── helpers.go
│ ├── auth.go
│ ├── link.go
│ ├── cuslinks.go
│ ├── article.go
│ └── index.go
├── middleware
│ ├── monitor.go
│ └── check_login.go
├── init.go
├── cli
│ └── cli.go
├── redis
│ └── redis.go
├── web
│ └── router.go
├── api
│ └── router.go
├── srv
│ ├── run.go
│ ├── web.go
│ └── api.go
├── model
│ └── types.go
└── mosaic
│ └── mosaic.go
├── .gitattributes
├── public
├── yc.png
├── zz.png
├── list.png
├── favicon.ico
├── payme.jpg
├── placeholder.jpg
├── stat.js
└── styles
│ └── site.css
├── Dockerfile
├── views
├── shared
│ ├── _footer.html
│ ├── _info.html
│ ├── _common.html
│ ├── _articles.html
│ ├── _cuslinks.html
│ ├── layout.html
│ ├── _group.html
│ └── _toper.html
├── detail.html
├── mosaic.html
├── cuslinks.html
├── choose.html
├── articles.html
├── links.html
├── index.html
└── payme.html
├── main.go
├── .gitignore
├── conf
└── config.json
├── LICENSE
├── go.mod
├── README.md
├── hrefs.cn.sql
└── go.sum
/src/utils/file.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.html linguist-language=go
--------------------------------------------------------------------------------
/public/yc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iissy/goweb/HEAD/public/yc.png
--------------------------------------------------------------------------------
/public/zz.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iissy/goweb/HEAD/public/zz.png
--------------------------------------------------------------------------------
/public/list.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iissy/goweb/HEAD/public/list.png
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iissy/goweb/HEAD/public/favicon.ico
--------------------------------------------------------------------------------
/public/payme.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iissy/goweb/HEAD/public/payme.jpg
--------------------------------------------------------------------------------
/public/placeholder.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iissy/goweb/HEAD/public/placeholder.jpg
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM alpine
2 | COPY ./server /server
3 | EXPOSE 80/tcp
4 | VOLUME ["/public", "/views"]
5 | ENTRYPOINT ["/server"]
--------------------------------------------------------------------------------
/views/shared/_footer.html:
--------------------------------------------------------------------------------
1 | Copyright ©2018 爱斯园 粤ICP备2020117325号-2
2 |
--------------------------------------------------------------------------------
/views/shared/_info.html:
--------------------------------------------------------------------------------
1 |
6 |
7 |
{{.body.Title}}
8 |
9 |
10 | {{.body.Body}}
11 |
12 |
13 | Posted by 何敏 on {{.body.CreateTime.Format "2006/1/2 15:04:05"}}
14 |
15 |
--------------------------------------------------------------------------------
/src/controller/linkcat.go:
--------------------------------------------------------------------------------
1 | package controller
2 |
3 | import (
4 | "github.com/gin-gonic/gin"
5 | "github.com/iissy/goweb/src/cli"
6 | "github.com/iissy/goweb/src/model"
7 | "github.com/iissy/goweb/src/utils"
8 | )
9 |
10 | func GetCatOptions(ctx *gin.Context) {
11 | result := new(model.LinkCatList)
12 | err := cli.Call("GetCatOptions", true, result)
13 | utils.WriteErrorLog(ctx.FullPath(), err)
14 |
15 | ctx.JSON(200, result.List)
16 | }
17 |
--------------------------------------------------------------------------------
/src/utils/errors.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import (
4 | "github.com/juju/errors"
5 | "github.com/sirupsen/logrus"
6 | )
7 |
8 | func checkErr(err error, msg string) {
9 | if err != nil {
10 | logrus.Fatalln(msg, err)
11 | }
12 | }
13 |
14 | func WriteErrorLog(path string, err error) bool {
15 | if err != nil {
16 | logrus.Errorf("%s, url = %s", errors.ErrorStack(err), path)
17 | return true
18 | } else {
19 | return false
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/conf/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "mysql": {
3 | "hrefs": "root:123456@tcp(192.168.111.151:3306)/hrefsdb?charset=utf8",
4 | "MaxIdleConns": 5,
5 | "MaxOpenConns": 50,
6 | "gorp": {
7 | "trace-on": false
8 | }
9 | },
10 | "redis": {
11 | "host": "192.168.111.151",
12 | "port": 6379
13 | },
14 | "consul": [{
15 | "host": "192.168.111.151",
16 | "port": 8500
17 | }],
18 | "srv": "micro.hrefs.srv",
19 | "domain": "localhost"
20 | }
--------------------------------------------------------------------------------
/src/middleware/monitor.go:
--------------------------------------------------------------------------------
1 | package middleware
2 |
3 | import (
4 | "github.com/gin-gonic/gin"
5 | "github.com/kataras/iris/v12"
6 | "github.com/sirupsen/logrus"
7 | "time"
8 | )
9 |
10 | func TraceWeb(ctx iris.Context) {
11 | defer trace(ctx.Path())()
12 | ctx.Next()
13 | }
14 |
15 | func TraceApi(ctx *gin.Context) {
16 | defer trace(ctx.Request.URL.Path)()
17 | ctx.Next()
18 | }
19 |
20 | func trace(path string) func() {
21 | start := time.Now()
22 | return func() {
23 | logrus.Infof("%s %s", time.Since(start), path)
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/utils/config.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import (
4 | "fmt"
5 | "github.com/asim/go-micro/v3/config"
6 | "log"
7 | )
8 |
9 | type Address struct {
10 | Host string `json:"host"`
11 | Port int `json:"port"`
12 | }
13 |
14 | var urls []string
15 |
16 | func GetConsulUrls() []string {
17 | addr := make([]Address, 0)
18 | if err := config.Get("consul").Scan(&addr); err != nil {
19 | log.Panic(err)
20 | }
21 |
22 | for _, addr := range addr {
23 | urls = append(urls, fmt.Sprintf("%s:%d", addr.Host, addr.Port))
24 | }
25 |
26 | return urls
27 | }
28 |
--------------------------------------------------------------------------------
/src/init.go:
--------------------------------------------------------------------------------
1 | package src
2 |
3 | import (
4 | "github.com/iissy/goweb/src/domain"
5 | "github.com/iissy/goweb/src/redis"
6 | "github.com/iissy/goweb/src/utils"
7 | "github.com/asim/go-micro/v3/config"
8 | "github.com/asim/go-micro/v3/config/source/file"
9 | "log"
10 | )
11 |
12 | const (
13 | defaultConfigPath = "conf/config.json"
14 | )
15 |
16 | func init() {
17 | loadConfig()
18 | utils.InitLog()
19 | domain.InitDb()
20 | redis.InitDb()
21 | }
22 |
23 | func loadConfig() {
24 | if err := config.Load(file.NewSource(
25 | file.WithPath(defaultConfigPath),
26 | )); err != nil {
27 | log.Panic(err)
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/cli/cli.go:
--------------------------------------------------------------------------------
1 | package cli
2 |
3 | import (
4 | "context"
5 | "fmt"
6 |
7 | "github.com/asim/go-micro/v3/client"
8 | "github.com/asim/go-micro/v3/config"
9 | )
10 |
11 | var name string
12 |
13 | func init() {
14 | name = config.Get("srv").String("micro.hrefs.srv")
15 | }
16 |
17 | func Call(method string, req interface{}, rsp interface{}) error {
18 | request := client.NewRequest(name, fmt.Sprintf("Hrefs.%s", method), req, client.WithContentType("application/json"))
19 |
20 | if err := client.Call(context.TODO(), request, &rsp); err != nil {
21 | fmt.Println(err)
22 | return err
23 | }
24 |
25 | return nil
26 | }
27 |
--------------------------------------------------------------------------------
/src/utils/redis.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import (
4 | "fmt"
5 | "github.com/gomodule/redigo/redis"
6 | "github.com/juju/errors"
7 | "github.com/asim/go-micro/v3/config"
8 | "time"
9 | )
10 |
11 | func InitRedisPool() *redis.Pool {
12 | host := config.Get("redis", "host").String("192.168.111.151")
13 | port := config.Get("redis", "port").Int(6379)
14 | return &redis.Pool{
15 | MaxIdle: 3,
16 | MaxActive: 20,
17 | IdleTimeout: time.Duration(180) * time.Second,
18 | Dial: func() (redis.Conn, error) {
19 | c, err := redis.Dial("tcp", fmt.Sprintf("%s:%d", host, port))
20 | if err != nil {
21 | return nil, errors.Trace(err)
22 | }
23 | c.Do("SELECT", 0)
24 | return c, nil
25 | },
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/domain/linkcat.go:
--------------------------------------------------------------------------------
1 | package domain
2 |
3 | import (
4 | "github.com/iissy/goweb/src/model"
5 | "github.com/juju/errors"
6 | )
7 |
8 | func GetCatOptions() ([]*model.LinkCat, error) {
9 | result := make([]*model.LinkCat, 0)
10 | sql := "SELECT id,catname FROM linkcat ORDER BY id desc"
11 | _, err := dbMap.Select(&result, sql)
12 | if err != nil {
13 | return nil, errors.Trace(err)
14 | }
15 |
16 | return result, nil
17 | }
18 |
19 | func GetLinkCat(id string) (*model.LinkCat, error) {
20 | result := new(model.LinkCat)
21 | sql := "SELECT id,catname FROM linkcat where id = ?"
22 | err := dbMap.SelectOne(&result, sql, id)
23 | if err != nil {
24 | return nil, errors.Trace(err)
25 | }
26 |
27 | return result, nil
28 | }
29 |
--------------------------------------------------------------------------------
/src/middleware/check_login.go:
--------------------------------------------------------------------------------
1 | package middleware
2 |
3 | import (
4 | "github.com/gin-gonic/gin"
5 | "github.com/iissy/goweb/src/cli"
6 | "github.com/iissy/goweb/src/utils"
7 | "github.com/juju/errors"
8 | "github.com/sirupsen/logrus"
9 | )
10 |
11 | func CheckLogin(ctx *gin.Context) {
12 | id := ParseHeadOrCookie(ctx, utils.ASYUSERID)
13 | token := ParseHeadOrCookie(ctx, utils.ASYTOKEN)
14 |
15 | if len(id) <= 0 || len(token) <= 0 {
16 | logrus.Error("miss id or token")
17 | ctx.Abort()
18 | return
19 | }
20 |
21 | v := new(string)
22 | err := cli.Call("GetToken", id, v)
23 | if err != nil {
24 | logrus.Error(errors.ErrorStack(err))
25 | ctx.Abort()
26 | return
27 | }
28 |
29 | if *v != token {
30 | ctx.Abort()
31 | }
32 | }
33 |
34 | func ParseHeadOrCookie(ctx *gin.Context, k string) string {
35 | v := ctx.GetHeader(k)
36 | if len(v) == 0 {
37 | v, _ = ctx.Cookie(k)
38 | }
39 | return v
40 | }
41 |
--------------------------------------------------------------------------------
/views/mosaic.html:
--------------------------------------------------------------------------------
1 | {{ define "mosaic-title"}}
2 |
13 |
14 | {{range .Active.Items}}
{{end}}
17 |
18 |
19 | {{range .Rests}}
20 |
21 | {{range .Items}}
{{end}}
24 |
25 | {{end}}
26 |
--------------------------------------------------------------------------------
/views/articles.html:
--------------------------------------------------------------------------------
1 | {{ define "articles-title"}}
2 |