这样正确
command: ["sh", "-c", "mysql -h${DC_DB_HOST} -uroot -p${MYSQL_ROOT_PASSWORD} ${MYSQL_DATABASE} < ./db/sql/latest_dump.sql"] 这样错误
command: ["mysql -h${DC_DB_HOST} -uroot -p${MYSQL_ROOT_PASSWORD} ${MYSQL_DATABASE} < ./db/sql/latest_dump.sql"] 这样也错误
command: "mysql -h${DC_DB_HOST} -uroot -p${MYSQL_ROOT_PASSWORD} ${MYSQL_DATABASE} < ./db/sql/latest_dump.sql"

makefile:

first step you should build a file name xxx.sh

and then you should make it can execute use command "chomd +x xxx.sh"

reference: http://tsov.net/sh-script-syntax/

rsync:

local to remote :

rsync -avz ./db root@xxxx:/root/

and then it will create a dirctory like /root/db

and -a means recur send document

and -v means show in detils

and -z means zip it to transport

--------------

remote to local

rsync -avz root@xxxx:/root/db .

and it will auto craete dictory in local like ./db

pay attion:

if you have a local file name xxx.sh and remote didn`t, it nothing happend

if you have a local file name xxx.sh and remote also but their different.

  1、remote to local and then the local file will replace by the remote file

2、local to remove and then the remote file will replace by the local file

referencehttp://man.linuxde.net/rsync

Dockerfile

* if you use ./server/main to start the server and then your .gtml file shoule put on the database-work dirctory beause that is the 相对目录

也就是相对目录是相对于你运行的路径????有待验证

and then the dockerfile must use ./

FROM golang:1.9.-alpine3.

COPY . $GOPATH/src/database-work

WORKDIR $GOPATH/src/database-work/server

RUN go build -o main main.go

ENTRYPOINT ["./main"]

# must use ./main

一般你的dockerfile会这样写,需要写上workdir,但是由于你的.go往往会有"github.com/xxx/xxx"

所以被迫你的dockerfile的workdir也就是你现在工程的workdir了

shell file

* in the first letter can not get space

#!/bin/bash

不能有空格,在#和!中

golang -- flag

每一个flag只能解析一次,res := flag.String("onlyone", default_value, dafault_use)

然后用go run main.go -onlyone 5是可以的

go run main.go --onlyone 5也是可以的

如果是bool,直接go run main.go -boolvalue就可以认为是true

word && wordint不冲突,都可以用

// [_Command-line flags_](http://en.wikipedia.org/wiki/Command-line_interface#Command-line_option)
// are a common way to specify options for command-line
// programs. For example, in `wc -l` the `-l` is a
// command-line flag. package main // Go provides a `flag` package supporting basic
// command-line flag parsing. We'll use this package to
// implement our example command-line program.
import "flag"
import "fmt" func main() { // Basic flag declarations are available for string,
// integer, and boolean options. Here we declare a
// string flag `word` with a default value `"foo"`
// and a short description. This `flag.String` function
// returns a string pointer (not a string value);
// we'll see how to use this pointer below.
wordPtr := flag.String("word", "default_word", "a string") // This declares `numb` and `fork` flags, using a
// similar approach to the `word` flag.
numbPtr := flag.Int("wordnumb", , "an int"). // 这样也可以,前缀相同
// nextPtr := flag.Int("numb", 0, "an int")
boolPtr := flag.Bool("fork", false, "a bool") // It's also possible to declare an option that uses an
// existing var declared elsewhere in the program.
// Note that we need to pass in a pointer to the flag
// declaration function.
var svar string
flag.StringVar(&svar, "svar", "defalut_var", "a string var") // Once all flags are declared, call `flag.Parse()`
// to execute the command-line parsing.
flag.Parse() // Here we'll just dump out the parsed options and
// any trailing positional arguments. Note that we
// need to dereference the pointers with e.g. `*wordPtr`
// to get the actual option values.
fmt.Println("word:", *wordPtr)
fmt.Println("numb:", *numbPtr)
fmt.Println("fork:", *boolPtr)
// fmt.Println("next:", *nextPtr)
fmt.Println("svar:", svar)
fmt.Println("tail:", flag.Args())
}

在shell文件中写一个,自动生成  时间+名字的文件

首先肯定是用touch命令,然后的话,我写了这样

function migrate() {
version=`date +%s` if [ ${defaultname}x == ""x ]
then defaultname="defaultname"
fi touch ./db/migrations/${version}_${defaultname}.up.sql
touch ./db/migrations/${version}_${defaultname}.down.sql
}

直接在terminal中用db.sh migrate name  是可以的。但是去到make migrate name就不行了。不知为何

然后说说那个判定。首先肯定要fi结尾。。。。

然后 https://blog.csdn.net/goodlixueyong/article/details/6564591

具体就是说我的$defaultname可能木有值吧,然后就变成了    == "defaultname"

也就是左边没有了,所以不行。然后同时加个其他字符就好了。

最后说说那个参数,defaultname,只能在外面写,不能去到某一个函数里写哦。

在docker-compose里调用shell文件

  dbrestore:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- DC_DB_HOST=${DC_DB_HOST}
- DC_DB_SSL_MODE=${DC_DB_SSL_MODE}
- MYSQL_DATABASE=${MYSQL_DATABASE}
volumes:
- ../db:/db
- ../tools:/tools
depends_on:
- db
links:
- db
command: "./tools/deploy.sh dbrestore"

.env文件是给docker-compose文件用的,docker-compose里每一个enviroment才是给docerfile或者外面那些shell文件用的

如果不加globlelock,那么100个相同的id进来了,就GG

如果加了,相同的id会被锁住,让一个id先进行成功了,解锁了,然后需要再判断一次,然后就会发现已经存在了。

package seq

import (
"sync" "github.com/sundayfun/daycam-server/db"
"github.com/sundayfun/daycam-server/db/model"
) // TODO: fix temp seq id var (
userMutex = make(map[uint64]*sync.Mutex)
existUser = make(map[uint64]uint64)
lock = &sync.Mutex{}
) const (
base =
) func init() {
} func whetherExist(uid uint64) uint64 {
if seq, ok := existUser[uid]; ok {
userMutex[uid].Lock()
defer userMutex[uid].Unlock() existUser[uid] = seq +
return seq
} return // zero refer to does not exist
} func NextSequenceIDByUser(uid uint64) uint64 { seq := whetherExist(uid)
if seq != { // user exist
return seq
} lock.Lock()
defer lock.Unlock() seq = whetherExist(uid)
if seq != { // user exist
return seq
} // first time to start main.go userMutex[uid] = &sync.Mutex{}
userMutex[uid].Lock()
defer userMutex[uid].Unlock() seq := model.LatestSeqByUser(db.GlobalDB, uid) existUser[uid] = seq +
return seq +
}

最新文章

  1. Python学习笔记2-解析数据
  2. (转载)SQL删除重复数据方法
  3. RabbitMq 集群配置
  4. JavaScript Patterns 5.7 Object Constants
  5. java 获取页面中的 a 标签 的 href 实例
  6. 微凉大大,教你一步一步在linux中正确的安装Xcache加速php。
  7. R语言笔记3--实例1
  8. windows应用程序框架及实例
  9. python将文本转化成语音并播放
  10. ASP.NET MVC5+EF6+EasyUI 后台管理系统(90)-EF 扩展操作
  11. Git与GitHub学习笔记(四)合并远程分支
  12. Android Vsync 原理浅析
  13. 20165233 2017-2018-2 《Java程序设计》课程总结
  14. Redis的复制特性
  15. requests.get()解析
  16. PyQt4布局管理——绝对定位方式
  17. linux 学习第十一天
  18. CCNA2.0笔记_WAN技术-帧中继
  19. 自己写的一个简单PHP采集器
  20. my01_Mysql router 安装

热门文章

  1. HTML5应用程序缓存Application Cache详解.RP
  2. C++二进制文件读写
  3. LeetCode第70题:爬楼梯
  4. ZOJ 2301 Color the Ball (离散化+线段树)
  5. C#实现远程开机(局域网测试通过)
  6. CentOS6.5上Zabbix3.0的RPM安装【二】-汉化
  7. 抽象类(abstract class)和接口(Interface)的区别
  8. ECS简介
  9. Python——用os模块寻找指定目录(包括子目录)下所有图片文件
  10. Julia体验 语言基础