<commit_before># Echo Web
Go web framework Echo example. 
> Echo middleware [echo-mw](https://github.com/hb-go/echo-mw)

> Echo中文文档 [go-echo.org](http://go-echo.org/)

> Requires
- go1.8+
- Echo V3

> [在线演示](http://echo.www.hbchen.com/)

#### 目录
- [环境配置](#环境配置)
- [运行](#运行)
- [打包](#打包)
- [目录结构](#目录结构)
- [框架功能](#框架功能)
- [框架功能](#框架功能)
- [Confd管理配置](#confd%e7%ae%a1%e7%90%86%e9%85%8d%e7%bd%ae)
- [Docker部署](#docker%e9%83%a8%e7%bd%b2)

## 环境配置

##### 1.源码下载
```shell
$ cd $GOPATH/src
$ git clone <EMAIL>:hb-go/echo-web.git
```

##### 2.依赖安装
> [dep工具安装](https://github.com/golang/dep#usage)
```shell
$ cd echo_web/
$ dep ensure
```

##### 3.MySQL配置
```shell
# ./conf/conf.toml
[database]
name = "goweb_db"
user_name = "goweb_dba"
pwd  = "<PASSWORD>"
host = "127.0.0.1"
port = "3306"

# 测试数据库SQL脚本
./echo-web/res/db_structure.sql
```

##### 4.Redis、Memcached配置，可选

> 可选需修改session、cache的store配置
- session_store = "FILE"或"COOKIE"
- cache_store = "IN_MEMORY"


```shell
# ./conf/conf.toml
[redis]
server = "127.0.0.1:6379"
pwd = "<PASSWORD>"

[memcached]
server = "localhost:11211"
```

##### 5.子域名
```shell
# ./conf/conf.toml
[server]
addr = ":8080"
domain_api = "echo.api.localhost.com"
domain_web = "echo.www.localhost.com"

# 改host
$ vi /etc/hosts
127.0.0.1       echo.api.localhost.com
127.0.0.1       echo.www.localhost.com

# Nginx配置，可选
server{
    listen       80;
    server_name  echo.www.localhost.com echo.api.localhost.com;

    charset utf-8;

    location / {
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host            $http_host;

        proxy_pass http://127.0.0.1:8080;
    }
}
```

##### 6.Bindata打包工具，可选(运行可选，打包必选)
> [Bindata安装](https://github.com/jteeuwen/go-bindata#installation)

## 运行
```shell
# 首次运行必须带 -a -t，更新assets.go、template.go的资源路径为本地
$ ./run.sh [-a] [-t]        # -a -t 可选(须安装Bindata)，以debug方式更新assets、template的Bindata资源包

# 浏览器访问
http://echo.www.localhost.com      # Nginx代理
http://echo.www.localhost.com:8080 # 无代理

# OpenTracing
http://localhost:8700/traces
```

## 打包
> 打包静态资源及模板文件须[安装Bindata](https://github.com/jteeuwen/go-bindata#installation)

```shell
# 打包
$ ./build.sh 		    # 默认本机
$ ./build.sh -l		    # 打包Linux平台

# 运行<commit_msg>nginx代理支持websocket<commit_after># Echo Web
Go web framework Echo example. 
> Echo middleware [echo-mw](https://github.com/hb-go/echo-mw)

> Echo中文文档 [go-echo.org](http://go-echo.org/)

> Requires
- go1.8+
- Echo V3

> [在线演示](http://echo.www.hbchen.com/)

#### 目录
- [环境配置](#环境配置)
- [运行](#运行)
- [打包](#打包)
- [目录结构](#目录结构)
- [框架功能](#框架功能)
- [框架功能](#框架功能)
- [Confd管理配置](#confd%e7%ae%a1%e7%90%86%e9%85%8d%e7%bd%ae)
- [Docker部署](#docker%e9%83%a8%e7%bd%b2)

## 环境配置

##### 1.源码下载
```shell
$ cd $GOPATH/src
$ git clone <EMAIL>:hb-go/echo-web.git
```

##### 2.依赖安装
> [dep工具安装](https://github.com/golang/dep#usage)
```shell
$ cd echo_web/
$ dep ensure
```

##### 3.MySQL配置
```shell
# ./conf/conf.toml
[database]
name = "goweb_db"
user_name = "goweb_dba"
pwd  = "<PASSWORD>"
host = "127.0.0.1"
port = "3306"

# 测试数据库SQL脚本
./echo-web/res/db_structure.sql
```

##### 4.Redis、Memcached配置，可选

> 可选需修改session、cache的store配置
- session_store = "FILE"或"COOKIE"
- cache_store = "IN_MEMORY"


```shell
# ./conf/conf.toml
[redis]
server = "127.0.0.1:6379"
pwd = "<PASSWORD>"

[memcached]
server = "localhost:11211"
```

##### 5.子域名
```shell
# ./conf/conf.toml
[server]
addr = ":8080"
domain_api = "echo.api.localhost.com"
domain_web = "echo.www.localhost.com"

# 改host
$ vi /etc/hosts
127.0.0.1       echo.api.localhost.com
127.0.0.1       echo.www.localhost.com

# Nginx配置，可选
server{
    listen       80;
    server_name  echo.www.localhost.com echo.api.localhost.com echo.socket.localhost.com;

    charset utf-8;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}
```

##### 6.Bindata打包工具，可选(运行可选，打包必选)
> [Bindata安装](https://github.com/jteeuwen/go-bindata#installation)

## 运行
```shell
# 首次运行必须带 -a -t，更新assets.go、template.go的资源路径为本地
$ ./run.sh [-a] [-t]        # -a -t 可选(须安装Bindata)，以debug方式更新assets、template的Bindata资源包

# 浏览器访问
http://echo.www.localhost.com      # Nginx代理
http://echo.www.localhost.com:8080 # 无代理

# OpenTracing
http://localhost:8700/traces
```

## 打包
> 打包静态资源及模板文件须[安装Bindata](https://github.com/jteeuwen/go-bindata#installation)

```shell
# 打包
$ ./build.sh 		    # 默认本机
$ ./build.sh -l		    # 打包Linux平台

# 运行
{'fraction_non_alphanumeric': 0.2035612222466476, 'fraction_numerical': 0.039569136073862386, 'mean_word_length': 3.4783464566929134, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 25, 'https://': 8, 'lorem ipsum': 0, 'www.': 12, 'xml': 0}, 'pii_count': 10, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7068481', 'n_tokens_mistral': 2349, 'n_tokens_neox': 2341, 'n_words': 286}