招商银行

金融街笔记20180510

晚上回到家,猛然想起来和招商银行同行,竟然有18年。

当初我发现招商银行的几个特征①真皮沙发 ②薄荷糖或大白兔 ③千平米营业网点

后来陆续发现招商银行的一些特征,家庭内转账免费收纳在校大学生和家长,客户分级,引导客户去证券开户。

后来发现一条原则 适度领先,确保第一。

18年的坚持,真心不容易。

经叔平

金融街笔记20180511

经叔平,民生银行创始人,曾经担任全国工商联主席。

年轻太美好了。 年轻的时候遇到大人物,是大人物可以做的事情,我即使做不到也可以模仿。 年龄大了,遇到大人物,是大人物可以做到的事情,我压根做不到,只是想到立即臣服归顺获得一份工作。

鼓励趁年轻的时候多出去转转,增广见闻,遇到一个可以模仿的大人物。

经叔平老爷子,点亮了我的人生,让我的人生变得有意义。以前不知道该做什么,不敢想,也不知道往哪儿想。

Gin框架介绍

准备工作

  1. 确认本地环境的$GOPATH

    • Windows 下使用 echo %GOPATH%
    • Linux 下使用echo $GOPATH
  2. 获取远程包 go get github.com/gin-gonic/gin

    1
    2
    //升级安装请增加参数 -u
    go get -u github.com/gin-gonic/gin
  3. 输入go version确认本地环境的Golang版本

第一个案例程序

  1. 在您的$GOPATH目录下创建子文件夹 $GOPATH/src/gin-first
  2. 切换到上述子文件夹下创建 main.go
  3. 复制如下内容到main.go

First

  1. 创建如下文件夹 $GOPATH/src/gin-first
  2. 在上述文件夹下创建main.go
  3. 复制下面的内容到main.go
  4. 在命令行窗口中运行 go run main.go
  5. 在浏览器中打开 http://127.0.0.1:8080/ping可以看到返回内容pong

如果您使用macOSLinux,您也可以在Shell窗口中输入如下命令

1
curl http://127.0.0.1:8080/ping

看到返回 pong

1
2
3
4
5
6
7
8
9
10
11
12
13
package main

import "github.com/gin-gonic/gin"

func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run() // listen and serve on 0.0.0.0:8080
}

运行

  1. 上述子文件夹下运行 go run main.go
  2. 将看到输出内容 [GIN-debug] Listening and serving HTTP on :8080
  3. 打开浏览器访问 http://127.0.0.1:8080/ping 可以看到返回pong

Dockerfile for Alpine+Golang

在开发环境,测试环境下使用 GolangDocker 镜像。 目前使用两个Dockerfile,一个基于Alpine,一个基于CentOS

使用时请注意修改掉私人有关的内容,

  • 比如依赖的私人文件,您在docker build时找不到
  • 私人的Github授权文件

Dockerfile中完成如下几类动作

  1. 下载或更新到最新版本的的Golang,目前版本式1.12.3
  2. 设置时区到东八区
  3. 设置Golang所依赖的环境变量比如 GO15VENDOREXPERIMENT GO111MODULE GOROOT GOPATH
  4. 配置访问Githubssh
  5. 设置工作目录 WORKDIR $GOPATH/src
  6. 声明VOLUME ["/data/yourcorp"]
  7. 声明开放端口EXPOSE

Dockerfile for Alpine+Golang

特别注意本Dockerfile中直接从Golang官网下载最新版本,某些地区可能需要科学上网。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
FROM alpine:latest

RUN apk add --no-cache \
ca-certificates

# RUN echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/main' > /etc/apk/repositories \
# && echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/community' >>/etc/apk/repositories \
RUN apk update \
&& apk add tzdata \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone
# set up nsswitch.conf for Go's "netgo" implementation
# - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
# - Docker run --rm debian:stretch grep '^hosts:' /etc/nsswitch.conf
RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf

ENV GOLANG_VERSION 1.12.3

RUN set -eux; \
apk add --no-cache --virtual .build-deps bash gcc musl-dev openssl gcc musl-dev go git\
; \
export \
# set GOROOT_BOOTSTRAP such that we can actually build Go
GOROOT_BOOTSTRAP="$(go env GOROOT)" \
# ... and set "cross-building" related vars to the installed system's values so that we create a build targeting the proper arch
# (for example, if our build host is GOARCH=amd64, but our build env/image is GOARCH=386, our build needs GOARCH=386)
GOOS="$(go env GOOS)" \
GOARCH="$(go env GOARCH)" \
GOHOSTOS="$(go env GOHOSTOS)" \
GOHOSTARCH="$(go env GOHOSTARCH)" \
; \
# also explicitly set GO386 and GOARM if appropriate
# https://github.com/docker-library/golang/issues/184
apkArch="$(apk --print-arch)"; \
case "$apkArch" in \
armhf) export GOARM='6' ;; \
x86) export GO386='387' ;; \
esac; \
\
wget -O go.tgz "https://golang.org/dl/go$GOLANG_VERSION.src.tar.gz"; \
# echo 'bc1ef02bb1668835db1390a2e478dcbccb5dd16911691af9d75184bbe5aa943e *go.tgz' | sha256sum -c -; \
tar -C /usr/local -xzf go.tgz; \
rm go.tgz; \
\
cd /usr/local/go/src; \
./make.bash; \
\
rm -rf \
# https://github.com/golang/go/blob/0b30cf534a03618162d3015c8705dd2231e34703/src/cmd/dist/buildtool.go#L121-L125
/usr/local/go/pkg/bootstrap \
# https://golang.org/cl/82095
# https://github.com/golang/build/blob/e3fe1605c30f6a3fd136b561569933312ede8782/cmd/release/releaselet.go#L56
/usr/local/go/pkg/obj \
; \
export PATH="/usr/local/go/bin:/usr/bin:$PATH"; \
go version; \
git version
# apk del .build-deps
ENV GO15VENDOREXPERIMENT 1
ENV GO111MODULE on
ENV GOROOT /usr/local/go
ENV GOPATH /data/boyosoft/goBillProcess
# ENV DPPATH $GOPATH/src/vendor/github.com/cpfc/dp
ENV PATH $GOPATH/bin:$GOROOT/bin:$PATH

# ENV GOPATH /go
# ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH

# RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && \
# chmod -R 777 "$GOPATH" && \
RUN mkdir -p /root/.ssh
COPY authorized_keys /root/.ssh/authorized_keys
COPY id_rsa_github /root/.ssh/id_rsa_github
# COPY id_rsa_bigdata_prod /root/.ssh/id_rsa_bigdata_prod
COPY config /root/.ssh/config
COPY known_hosts /root/.ssh/known_hosts
RUN cd /root/.ssh; \
chmod 400 *; \
cd ..; \
chmod 700 .ssh; \
git config --global user.name "devuser"; \
git config --global user.email "pythoner@icloud.com"
#
WORKDIR $GOPATH/src
VOLUME ["/data/yourcorp"]
EXPOSE 8080 8081 3000 3001 9000 9001 9090

Dockerfile for CentOS+Golang

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Version: 0.0.1
FROM centos:latest
MAINTAINER devuser "devuser@yourcorp.net"
# RUN yum install -y wget
#================================================================
# 创建构建或初始化容器时的若干中文件
RUN mkdir /dockerdata
WORKDIR /dockerdata
ADD go1.12.3.linux-amd64.tar.gz /dockerdata
# 升级到centos-7
# COPY CentOS6-Base-163.repo /dockerdata/CentOS-Base.repo
# COPY geekery.repo /dockerdata/geekery.repo
# RUN mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup && \
# cp /dockerdata/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo && \
# cp /dockerdata/geekery.repo /etc/yum.repos.d/geekery.repo
RUN yum clean all && \
yum makecache && \
yum -y update && \
yum install -y gcc git
# RUN yum install -y curl && \

# yum install -y readline-devel && \
# yum install -y libXt-devel && \
# yum install -y make
# screen ftp
# RUN yum install -y gcc-gfortran

# gcc-c++
# RUN yum install -y readline-devel
# RUN yum install -y libXt-devel
# RUN yum install -y make
# git

#================================================================

# RUN yum install -y vixie-cron
# RUN yum install -y crontabs
# RUN chkconfig --level 35 crond on
# RUN yum install -y bzip2recover
# RUN yum install -y bzip2

# install R packages
# RUN yum install -y epel-release
# RUN yum install -y R
#================================================================
# RUN yum install -y mysql-community-server
# RUN yum install tomcat6 tomcat6-webapps tomcat6-admin-webapps
#================================================================
# RUN yum install -y redis-server
# RUN yum install -y redis-tools
#================================================================RUN eval "TZ='Asia/Shanghai'; export TZ"
RUN echo "export TZ=\"Asia/Shanghai\"" >> /root/.bashrc && \
echo "export TS=\"`date -d today +"%-Y%-m%-d%k%M%S"`\"" >> /root/.bashrc && \
echo "export VERSION=\"`date -d today +"v2.4.0.%-Y%-m%-d%-k%M%S"`\"" >> /root/.bashrc && \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#@todo: 争取把跨平台编译的脚本保存在Docker容器中
# RUN echo `for GOOS in windows;do for GOARCH in 386 amd64; do go build -v -ldflags "-s -w -X main._VERSION_="$VERSION -o BillProcess-$GOOS-$GOARCH-v$TS.exe; done; done`

# RUN rm /etc/localtime3

#================================================================
# 此处纯粹是为配合腾讯的习惯,腾讯虚拟服务器的工作卷名字叫data
# RUN export http_proxy="10.251.233.145:8888"
# RUN export https_prxy="10.251.233.145:8888"
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8

#================================================================

#================================================================

RUN echo "47.92.84.245\tyourcorp" >> /dockerdata/ex_hosts && \
echo "47.92.84.245\tyourcorp.net" >> /dockerdata/ex_hosts && \
echo "47.92.84.245\twww.yourcorp.net" >> /dockerdata/ex_hosts && \
touch /dockerdata/update_hosts && \
echo "cat /dockerdata/ex_hosts >> /etc/hosts" >> /dockerdata/update_hosts && \
echo "/etc/init.d/netfs restart" >> /dockerdata/update_hosts && \
chmod 700 /dockerdata/update_hosts && \
rm -rf /dockerdata/ex_hosts && \
rm -rf /usr/lib/golang && \
cp -rf /dockerdata/go /usr/lib/golang && \
rm -rf /dockerdata/go && \
mkdir -p /root/.ssh && \
chmod 700 /root/.ssh

ENV GO15VENDOREXPERIMENT 1
ENV GO111MODULE on
ENV GOROOT /usr/lib/golang
ENV GOPATH /data/yourcorp/goBillProcess
# ENV DPPATH $GOPATH/src/vendor/github.com/cpfc/dp
ENV PATH $GOPATH/bin:$GOROOT/bin:$PATH

#================================================================
# ADD getlatest.sh /dockerdata/getlatest.sh

RUN mkdir -p /root/.ssh
COPY authorized_keys /root/.ssh/authorized_keys
COPY id_rsa_github /root/.ssh/id_rsa_github
# COPY id_rsa_bigdata_prod /root/.ssh/id_rsa_bigdata_prod
COPY config /root/.ssh/config
COPY known_hosts /root/.ssh/known_hosts
RUN cd /root/.ssh && \
chmod 400 * && \
cd .. && \
chmod 700 .ssh

# RUN git clone git@git.18.tl:devuser/processtest.git gittest
# RUN git clone http://devuser:Pocketbbs@www.taolch.com:10080/git/goBillProcess.git

# RUN chmod 700 /dockerdata/getlatest.sh
#RUN echo "#!/bin/sh" >> /dockerdata/build-$APPNAME.sh; \
# echo "cd $APPAPIPATH" >> /dockerdata/build-$APPNAME.sh; \
# echo "go build -o $APPNAME main.go" >> /dockerdata/build-$APPNAME.sh; \
# echo "scp $APPNAME 192.168.200.244:~/$APPNAME" >> /dockerdata/build-$APPNAME.sh; \
# chmod 700 /dockerdata/build-$APPNAME.sh

# RUN echo "#!/bin/sh" >> /dockerdata/build-$APPNAME.sh; \
# echo "cd $APPAPIPATH" >> /dockerdata/build-$APPNAME.sh; \
# echo "go build -o $APPNAME $APPNAME.go" >> /dockerdata/build-$APPNAME.sh; \
# echo "scp $APPNAME 10.104.19.122:~/data/yourcorp/$APPNAME" >> /dockerdata/build-$APPNAME.sh; \
# chmod 700 /dockerdata/build-$APPNAME.sh

# RUN git config --global user.email "devuser@yourcorp.net"
# RUN git config --global user.name "devuser"
# RUN git config --global push.default matching
RUN git config --global user.name "devuser"
RUN git config --global user.email "pythoner@icloud.com"

###############################################################################
# 初始化root用户的环境变量
RUN echo "export GOPATH=$GOPATH" >> /root/.bashrc && \
echo "export GOROOT=$GOROOT" >> /root/.bashrc && \
echo "export GO15VENDOREXPERIMENT=$GO15VENDOREXPERIMENT" >> /root/.bashrc && \
echo "export GO111MODULE=$GO111MODULE" >> /root/.bashrc && \
echo "export JDALPHASERVERPATH=$GOPATH/src/github.com/yourcorp/jdalphaserver" >> /root/.bashrc && \
echo "export PATH=$PATH" >> /root/.bashrc && \
cat /root/.bashrc && \
rm -rf /var/cache/yum
# RUN source /root/.profile
# RUN touch /usr/local/bin/q && \
# chmod +x /usr/local/bin/q && \
# echo "#!/bin/bash" >> /usr/local/bin/q && \
# echo "cd $JDALPHASERVERPATH" >> /usr/local/bin/q && \
# echo "rm -rf jdalphaserver" >> /usr/local/bin/q && \
# echo "go build" >> /usr/local/bin/q && \
# echo "chmod +x jdalphaserver" >> /usr/local/bin/q && \
# # echo "./jdalphaserver -syncdb" >> /usr/local/bin/q && \
# echo "./jdalphaserver" >> /usr/local/bin/q
###############################################################################

#RUN mkdir -p /dockerdata/www/html/static
# RUN git commit -a -m "update when compile the dockerfile"
# RUN git push
# goBillProcess内嵌的Web服务器占用的端口号
WORKDIR $GOPATH/src
VOLUME ["/data/yourcorp"]
EXPOSE 8080 8081 3000 3001 9000 9001 9090

# export VERSION=`date -d today +"v2.4.0.%-Y%-m%-d%-k%M%S"`
# export TS=`date -d today +"%-Y%-m%-d%k%M%S"`
# for GOOS in windows;do for GOARCH in 386 amd64; do go build -v -ldflags "-s -w -X main._VERSION_="$VERSION -o BillProcess-$GOOS-$GOARCH-v$TS.exe; done; done

# ENTRYPOINT ["/root/config_crond.sh"]
# CMD ["/dockerdata/build-$APPNAME.sh"]

卢作孚

卢作孚

金融街笔记20180525

建国初年,毛泽东曾对黄炎培说:在中国近代历史上,有4个人是我们万万不可忘记的,他们是:搞重工业的张之洞;搞纺织工业的张謇;搞交通运输业的卢作孚;搞化学工业的范旭东。这其中的卢作孚跨越了”革命救国”、”教育救国”、”实业救国”三大领域,并且在几个方面都各有成就。

图片发自简书App

图片发自简书App

图片发自简书App

图片发自简书App

图片发自简书App

图片发自简书App

十六七岁读卢作孚传 ①他开通长江上游轮船航运,运送川中物资出川。 ②抗日内迁他支持常公从武汉搬运机械设备军火上送到重庆,自备柴油。 ③缙云山豆花饭宴请常公,暗示蜀中百姓疾苦。 ④办学支持科学事业。

Dockerfile for Alpine+Golang

Dockerfile for Alpine+Golang

在开发环境,测试环境下使用Golang的Docker镜像。 目前使用两个Dockerfile,一个基于Alpine,一个基于CentOS。

使用时请注意修改掉私人有关的内容。

Dockerfile for Alpine+Golang

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
FROM alpine:latest

RUN apk add --no-cache \
ca-certificates

# set up nsswitch.conf for Go's "netgo" implementation
# - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
# - Docker run --rm debian:stretch grep '^hosts:' /etc/nsswitch.conf
RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf

ENV GOLANG_VERSION 1.12.3

RUN set -eux; \
apk add --no-cache --virtual .build-deps bash gcc musl-dev openssl gcc musl-dev go git\
; \
export \
# set GOROOT_BOOTSTRAP such that we can actually build Go
GOROOT_BOOTSTRAP="$(go env GOROOT)" \
# ... and set "cross-building" related vars to the installed system's values so that we create a build targeting the proper arch
# (for example, if our build host is GOARCH=amd64, but our build env/image is GOARCH=386, our build needs GOARCH=386)
GOOS="$(go env GOOS)" \
GOARCH="$(go env GOARCH)" \
GOHOSTOS="$(go env GOHOSTOS)" \
GOHOSTARCH="$(go env GOHOSTARCH)" \
; \
# also explicitly set GO386 and GOARM if appropriate
# https://github.com/docker-library/golang/issues/184
apkArch="$(apk --print-arch)"; \
case "$apkArch" in \
armhf) export GOARM='6' ;; \
x86) export GO386='387' ;; \
esac; \
\
wget -O go.tgz "https://golang.org/dl/go$GOLANG_VERSION.src.tar.gz"; \
# echo 'bc1ef02bb1668835db1390a2e478dcbccb5dd16911691af9d75184bbe5aa943e *go.tgz' | sha256sum -c -; \
tar -C /usr/local -xzf go.tgz; \
rm go.tgz; \
\
cd /usr/local/go/src; \
./make.bash; \
\
rm -rf \
# https://github.com/golang/go/blob/0b30cf534a03618162d3015c8705dd2231e34703/src/cmd/dist/buildtool.go#L121-L125
/usr/local/go/pkg/bootstrap \
# https://golang.org/cl/82095
# https://github.com/golang/build/blob/e3fe1605c30f6a3fd136b561569933312ede8782/cmd/release/releaselet.go#L56
/usr/local/go/pkg/obj \
; \
export PATH="/usr/local/go/bin:/usr/bin:$PATH"; \
go version; \
git version
# apk del .build-deps
ENV GO15VENDOREXPERIMENT 1
ENV GO111MODULE on
ENV GOROOT /usr/local/go
ENV GOPATH /data/boyosoft/goBillProcess
# ENV DPPATH $GOPATH/src/vendor/github.com/cpfc/dp
ENV PATH $GOPATH/bin:$GOROOT/bin:$PATH

# ENV GOPATH /go
# ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH

# RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && \
# chmod -R 777 "$GOPATH" && \
RUN mkdir -p /root/.ssh
COPY authorized_keys /root/.ssh/authorized_keys
COPY id_rsa_github /root/.ssh/id_rsa_github
# COPY id_rsa_bigdata_prod /root/.ssh/id_rsa_bigdata_prod
COPY config /root/.ssh/config
COPY known_hosts /root/.ssh/known_hosts
RUN cd /root/.ssh; \
chmod 400 *; \
cd ..; \
chmod 700 .ssh; \
git config --global user.name "devuser"; \
git config --global user.email "pythoner@icloud.com"
#
WORKDIR $GOPATH/src
VOLUME ["/data/boyosoft"]
EXPOSE 8080 8081 3000 3001 9000 9001 9090

Dockerfile for CentOS+Golang

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Version: 0.0.1
FROM centos:latest
MAINTAINER xiehuanang "xiehuanang@boyosoft.net"
# RUN yum install -y wget
#================================================================
# 创建构建或初始化容器时的若干中文件
RUN mkdir /dockerdata
WORKDIR /dockerdata
ADD go1.12.3.linux-amd64.tar.gz /dockerdata
# 升级到centos-7
# COPY CentOS6-Base-163.repo /dockerdata/CentOS-Base.repo
# COPY geekery.repo /dockerdata/geekery.repo
# RUN mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup && \
# cp /dockerdata/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo && \
# cp /dockerdata/geekery.repo /etc/yum.repos.d/geekery.repo
RUN yum clean all && \
yum makecache && \
yum -y update && \
yum install -y gcc git
# RUN yum install -y curl && \

# yum install -y readline-devel && \
# yum install -y libXt-devel && \
# yum install -y make
# screen ftp
# RUN yum install -y gcc-gfortran

# gcc-c++
# RUN yum install -y readline-devel
# RUN yum install -y libXt-devel
# RUN yum install -y make
# git

#================================================================

# RUN yum install -y vixie-cron
# RUN yum install -y crontabs
# RUN chkconfig --level 35 crond on
# RUN yum install -y bzip2recover
# RUN yum install -y bzip2

# install R packages
# RUN yum install -y epel-release
# RUN yum install -y R
#================================================================
# RUN yum install -y mysql-community-server
# RUN yum install tomcat6 tomcat6-webapps tomcat6-admin-webapps
#================================================================
# RUN yum install -y redis-server
# RUN yum install -y redis-tools
#================================================================RUN eval "TZ='Asia/Shanghai'; export TZ"
RUN echo "export TZ=\"Asia/Shanghai\"" >> /root/.bashrc && \
echo "export TS=\"`date -d today +"%-Y%-m%-d%k%M%S"`\"" >> /root/.bashrc && \
echo "export VERSION=\"`date -d today +"v2.4.0.%-Y%-m%-d%-k%M%S"`\"" >> /root/.bashrc && \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#@todo: 争取把跨平台编译的脚本保存在Docker容器中
# RUN echo `for GOOS in windows;do for GOARCH in 386 amd64; do go build -v -ldflags "-s -w -X main._VERSION_="$VERSION -o BillProcess-$GOOS-$GOARCH-v$TS.exe; done; done`

# RUN rm /etc/localtime3

#================================================================
# 此处纯粹是为配合腾讯的习惯,腾讯虚拟服务器的工作卷名字叫data
# RUN export http_proxy="10.251.233.145:8888"
# RUN export https_prxy="10.251.233.145:8888"
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8

#================================================================

#================================================================

RUN echo "47.92.84.245\tboyosoft" >> /dockerdata/ex_hosts && \
echo "47.92.84.245\tboyosoft.net" >> /dockerdata/ex_hosts && \
echo "47.92.84.245\twww.boyosoft.net" >> /dockerdata/ex_hosts && \
touch /dockerdata/update_hosts && \
echo "cat /dockerdata/ex_hosts >> /etc/hosts" >> /dockerdata/update_hosts && \
echo "/etc/init.d/netfs restart" >> /dockerdata/update_hosts && \
chmod 700 /dockerdata/update_hosts && \
rm -rf /dockerdata/ex_hosts && \
rm -rf /usr/lib/golang && \
cp -rf /dockerdata/go /usr/lib/golang && \
rm -rf /dockerdata/go && \
mkdir -p /root/.ssh && \
chmod 700 /root/.ssh

ENV GO15VENDOREXPERIMENT 1
ENV GO111MODULE on
ENV GOROOT /usr/lib/golang
ENV GOPATH /data/boyosoft/goBillProcess
# ENV DPPATH $GOPATH/src/vendor/github.com/cpfc/dp
ENV PATH $GOPATH/bin:$GOROOT/bin:$PATH

#================================================================
# ADD getlatest.sh /dockerdata/getlatest.sh

RUN mkdir -p /root/.ssh
COPY authorized_keys /root/.ssh/authorized_keys
COPY id_rsa_github /root/.ssh/id_rsa_github
# COPY id_rsa_bigdata_prod /root/.ssh/id_rsa_bigdata_prod
COPY config /root/.ssh/config
COPY known_hosts /root/.ssh/known_hosts
RUN cd /root/.ssh && \
chmod 400 * && \
cd .. && \
chmod 700 .ssh

# RUN git clone git@git.18.tl:xiehuanang/processtest.git gittest
# RUN git clone http://xiehuanang:Pocketbbs@www.taolch.com:10080/git/goBillProcess.git

# RUN chmod 700 /dockerdata/getlatest.sh
#RUN echo "#!/bin/sh" >> /dockerdata/build-$APPNAME.sh; \
# echo "cd $APPAPIPATH" >> /dockerdata/build-$APPNAME.sh; \
# echo "go build -o $APPNAME main.go" >> /dockerdata/build-$APPNAME.sh; \
# echo "scp $APPNAME 192.168.200.244:~/$APPNAME" >> /dockerdata/build-$APPNAME.sh; \
# chmod 700 /dockerdata/build-$APPNAME.sh

# RUN echo "#!/bin/sh" >> /dockerdata/build-$APPNAME.sh; \
# echo "cd $APPAPIPATH" >> /dockerdata/build-$APPNAME.sh; \
# echo "go build -o $APPNAME $APPNAME.go" >> /dockerdata/build-$APPNAME.sh; \
# echo "scp $APPNAME 10.104.19.122:~/data/boyosoft/$APPNAME" >> /dockerdata/build-$APPNAME.sh; \
# chmod 700 /dockerdata/build-$APPNAME.sh

# RUN git config --global user.email "xiehuanang@boyosoft.net"
# RUN git config --global user.name "xiehuanang"
# RUN git config --global push.default matching
RUN git config --global user.name "devuser"
RUN git config --global user.email "pythoner@icloud.com"

###############################################################################
# 初始化root用户的环境变量
RUN echo "export GOPATH=$GOPATH" >> /root/.bashrc && \
echo "export GOROOT=$GOROOT" >> /root/.bashrc && \
echo "export GO15VENDOREXPERIMENT=$GO15VENDOREXPERIMENT" >> /root/.bashrc && \
echo "export GO111MODULE=$GO111MODULE" >> /root/.bashrc && \
echo "export JDALPHASERVERPATH=$GOPATH/src/github.com/boyosoft/jdalphaserver" >> /root/.bashrc && \
echo "export PATH=$PATH" >> /root/.bashrc && \
cat /root/.bashrc && \
rm -rf /var/cache/yum
# RUN source /root/.profile
# RUN touch /usr/local/bin/q && \
# chmod +x /usr/local/bin/q && \
# echo "#!/bin/bash" >> /usr/local/bin/q && \
# echo "cd $JDALPHASERVERPATH" >> /usr/local/bin/q && \
# echo "rm -rf jdalphaserver" >> /usr/local/bin/q && \
# echo "go build" >> /usr/local/bin/q && \
# echo "chmod +x jdalphaserver" >> /usr/local/bin/q && \
# # echo "./jdalphaserver -syncdb" >> /usr/local/bin/q && \
# echo "./jdalphaserver" >> /usr/local/bin/q
###############################################################################

#RUN mkdir -p /dockerdata/www/html/static
# RUN git commit -a -m "update when compile the dockerfile"
# RUN git push
# goBillProcess内嵌的Web服务器占用的端口号
WORKDIR $GOPATH/src
VOLUME ["/data/boyosoft"]
EXPOSE 8080 8081 3000 3001 9000 9001 9090

# export VERSION=`date -d today +"v2.4.0.%-Y%-m%-d%-k%M%S"`
# export TS=`date -d today +"%-Y%-m%-d%k%M%S"`
# for GOOS in windows;do for GOARCH in 386 amd64; do go build -v -ldflags "-s -w -X main._VERSION_="$VERSION -o BillProcess-$GOOS-$GOARCH-v$TS.exe; done; done

# ENTRYPOINT ["/root/config_crond.sh"]
# CMD ["/dockerdata/build-$APPNAME.sh"]

牌照经济学

金融街笔记20180524

最重要的事情

  • 牌照经济学
  • 牌照经济学
  • 牌照经济学

下面还有三万句废话,我懒得敲出来。套用曾经混BBS的一句套话,本文正文如题,其他都是废话。

Windows下编译Golang

建议维持如下目录结构

1
2
3
foo -->src
-->bin
-->pkg

编译过程一般来说分成如下几步

  1. 前从 git/svn 服务器抓取最新的版本

  2. 清理现场

  3. 获得时间戳,以便在后续编译过程中带入作为版本号的后缀

  4. 编译,携带若干参数(资源文件、不含调试信息、版本号,目标文件名称)

  5. 复制到特定文件夹

  6. 连同配置文件一起压缩,压缩文件带有上述时间戳

  7. 导出源代码,并压缩,压缩文件带有上述时间戳

  8. 清理现场

上述步骤连续做下来,没有一个工程师可以可以连续无差错做两遍。 这样的场景适合创建一个批处理文件,如果在Linux下的话就是Shell脚本文件。

下面是一个批处理文件的示例,请参阅。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

@echo off
echo 编译打包命令如下
echo ==========================================
set /a t1=(1%time:~0,2%-100)*1
if %t1% LSS 10 set t1=0%t1%
set ymd_hm=%date:~0,4%%date:~5,2%%date:~8,2%%t1%%time:~3,2%%time:~6,2%
set "Version=v2.2.%ymd_hm%"
echo 版本号: %Version%
@echo on
go clean
go build -o YOUR_PROGRAMNAME.exe -ldflags "-s -w -X main._VERSION_ '%Version%'"
set PATH=%PATH%;C:\Program Files\WinRAR;
copy YOUR_PROGRAMNAME.exe "YOUR_PROGRAMNAME_v%ymd_hm%.exe"
rar a "YOUR_PROGRAMNAME_v%ymd_hm%.ra_" "YOUR_PROGRAMNAME_v%ymd_hm%.exe"
@echo off
echo ==========================================
@echo on

如果要支持上述代码中的,在编译命令中引入版本号,那么需要在源代码文件, 即包含 main 方法的 go 文件中包含如下变量定义。

1
2
3

//如下变量供编译器使用,不适用于golint的修改建议
var _VERSION_ = "unknown"

BTW

  1. golint 认为上述变量命名不符合规范,请忽略之

  2. 关于 Windows下批处理文件的更多知识,请 google

陈春花的故事

金融街笔记20180611

一四年冬天拜访一家八线城市郊区的冷库。

冷库的老板告诉我刚刚被新希望收购,考虑我可能不知道新希望,告诉我一家做饲料的公司。

我知道新希望,也知道陈到这家公司做客卿。

这家冷库从表面上看地处八线城市郊区,老板水平冷库面积,都没什么可圈可点之处。

但是仔细琢磨冷库这个案例,

  1. 地处三省交界,发达的公路网络可以冷链触达周边五省(冷链有距离限制)
  2. 老板做事情精致有追求皮鞋干净办公室整洁,苹果一体机
  3. 老板积极拥抱变化尝试粗糙的供应链金融
  4. 老板节制,老板回民经营冷库只接纳民族习惯认可的肉类,这需要多大的勇气。

自此对陈春花刮目相看。