查看执行程序当前路径

file, _ := exec.LookPath(os.Args[0])
path, _ := filepath.Abs(file)
println(path)

Byte2String

func B2S(buf []byte) string {
    return *(*string)(unsafe.Pointer(&buf))
}

String2Byte

func S2B(s *string) []byte {
    return *(*[]byte)(unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(s))))
}

package main

import (
    "database/sql"
    "fmt"
    _ "github.com/go-sql-driver/mysql"
)

func main() {
    db, err := sql.Open("mysql", "root:root@tcp(127.0.0.1:3306)/test?charset=utf8")

    if err != nil {
        panic(err.Error())
    }
    defer db.Close()

    rows, err := db.Query("select user_id,access_token from user_session")
    if err != nil {
        panic(err.Error())
    }

    var user_id int
    var access_token string

    for rows.Next() {
        err := rows.Scan(&user_id, &access_token)
        if err != nil {
            panic(err.Error())
        }
        fmt.Println(user_id, access_token)
    }

}

server
{
    listen 80;
    server_name xxx.com;

    location / {
        proxy_pass      http://xxx.com:8080;

        server_tokens           off;
        client_max_body_size    20m;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    #生成缩略图等比例
    if ($args ~ ^r\d+x\d+$) {
        rewrite ^(.+)$ $1/$args? last;
    }
    location ~* \.(gif|png|jpg|jpeg)/r(\d+)x(\d+)$ {
        root /data/www/sezign.com;
        set $w $2;
        set $h $3;

        if ( $w = 0 ) {
                set $w '-';
        }
        if ( $h = 0 ) {
                set $h '-';
        }

        rewrite ^(.+)/r(\d+)x(\d+)$ $1 break;

        image_filter resize  $w $h;
        image_filter_buffer  10M;
    }

    #生成裁切图片固定高宽
    if ($args ~ ^c\d+x\d+$) {
        rewrite ^(.+)$ $1/$args? last;
    }
    location ~* \.(gif|png|jpg|jpeg)/c(\d+)x(\d+)$ {
        root /data/www/sezign.com;
        set $w $2;
        set $h $3;

        if ( $w = 0 ) {
                set $w '-';
        }
        if ( $h = 0 ) {
                set $h '-';
        }

        rewrite ^(.+)/c(\d+)x(\d+)$ $1 break;

        image_filter crop  $2 $h;
        image_filter_buffer  10M;
    }
}

安装过程

Github-Qihoo360/Atlas 上下载Atlas-2.2-debian6.0-x86_64.deb

wget https://github.com/Qihoo360/Atlas/releases/download/2.2/Atlas-2.2-debian6.0-x86_64.deb

执行安装

dpkg -i Atlas-2.2-debian6.0-x86_64.deb

修改配置文件

待编辑

配置详情参考Github-Atlas的安装

启动服务遇错误

2016-08-18 14:13:01: (critical) loading module '/usr/local/mysql-proxy/lib/mysql-proxy/plugins/libproxy.so' failed: libmysqlclient.so.16: cannot open shared object file: No such file or directory
2016-08-18 14:13:01: (critical) setting --plugin-dir=<dir> might help
2016-08-18 14:13:01: (message) Initiating shutdown, requested from mysql-proxy-cli.c:432
2016-08-18 14:13:01: (message) shutting down normally, exit code is: 1

查找问题过程

apt-file search libmysqlclient

发现系统目录/usr/lib/x86_64-linux-gnu/下有/usr/lib/x86_64-linux-gnu/libmysqlclient.so.20

ln建连接

ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20 /usr/lib/x86_64-linux-gnu/libmysqlclient.so.16

失败报错如下

2016-08-18 16:39:29: (critical) loading module '/usr/local/mysql-proxy/lib/mysql-proxy/plugins/libproxy.so' failed: /usr/lib/x86_64-linux-gnu/libmysqlclient.so.16: version `libmysqlclient_16' not found (required by /usr/local/mysql-proxy/lib/mysql-proxy/plugins/libproxy.so)
2016-08-18 16:39:29: (critical) setting --plugin-dir=<dir> might help
2016-08-18 16:39:29: (message) Initiating shutdown, requested from mysql-proxy-cli.c:432
2016-08-18 16:39:29: (message) shutting down normally, exit code is: 1

删除连接 从csdn下载libmysqlclient.so.16文件
报错

2016-08-18 16:48:12: (critical) loading module '/usr/local/mysql-proxy/lib/mysql-proxy/plugins/libproxy.so' failed: libmysqlclient.so.16: wrong ELF class: ELFCLASS32
2016-08-18 16:48:12: (critical) setting --plugin-dir=<dir> might help
2016-08-18 16:48:12: (message) Initiating shutdown, requested from mysql-proxy-cli.c:432
2016-08-18 16:48:12: (message) shutting down normally, exit code is: 1

从CSDN从新下载了libmysqlclient.so.16(64bit)

服务启动成功。

root@ebs-39470:/usr/local/mysql-proxy/log# /usr/local/mysql-proxy/bin/mysql-proxyd test status
MySQL-Proxy of test is running (6127)
root@ebs-39470:/#mysql -h127.0.0.1 -P2345 -uuser -ppwd

mysql> select * from help;

+----------------------------+---------------------------------------------------------+
| command                    | description                                             |
+----------------------------+---------------------------------------------------------+
| SELECT * FROM help         | shows this help                                         |
| SELECT * FROM backends     | lists the backends and their state                      |
| SET OFFLINE $backend_id    | offline backend server, $backend_id is backend_ndx's id |
| SET ONLINE $backend_id     | online backend server, ...                              |
| ADD MASTER $backend        | example: "add master 127.0.0.1:3306", ...               |
| ADD SLAVE $backend         | example: "add slave 127.0.0.1:3306", ...                |
| REMOVE BACKEND $backend_id | example: "remove backend 1", ...                        |
| ADD CLIENT $client         | example: "add client 192.168.1.2", ...                  |
| REMOVE CLIENT $client      | example: "remove client 192.168.1.2", ...               |
| SAVE CONFIG                | save the backends to config file                        |
+----------------------------+---------------------------------------------------------+
10 rows in set (0.00 sec)

完结撒花~