2019/12/27

wechat subscribe message 订阅消息

1. 选择权回到用户手中。需要用户主动点击授权之后,小程序才能向其推送服务通知,
2、时长不受限制。「订阅消息」取消了7天内推送消息的时间限制,只要用户没有主动拒收消息推送,开发者就可以随时推送服务通知。



2019/12/25

docker image build Dockerfile

docker-compse.yml 内で定義  go のimage
image:xxx/xxx ->直接pull して使う

imageを調査する
 履歴調査 docker image history image_name
 構成調査 docker image inspect image_name

build a image from dockerfile
 docker build --help 

Dockerfile 原則
 1. container from Dockerfile  is ephemeral
 2. one container one process (easy to scale  horizontally)
 3. minimize container layer ( use one-line command. one command one layer)

   RUN apt-get update && apt-get install -y \
  bzr \
  cvs \
  git \
  mercurial \
  subversion

 4. docker build dockerfile_path (---no-cache=true)
     run commands in dockerfile to create layer.
     but first to search cache (sha256のchecksumがあり)あれば、使う。 

2019/12/24

ninson ignore

-ignore='Path .git' 
-ignore='Path .github' 
-ignore='Path docker-compose' 
-ignore='Path .idea' 
-ignore='Name *.gitignore'

docker mac performance

docker use linux kernel almost as native, so performance is well.
in mac or windows, things are different. there is no linux kernel.
so some helper needed.

docker-machine:   a tool to install docker in virtual machine. Dockerized hosts (hosts with Docker Engine on them).

docker for Mac/Windows:  even still run a virtual machine (super hidden ).with its own hypervisor “hyperkit” and shared file system “osxfs”. Unfortunately, “osxfs” wasn’t very fast.

but in many cases, realtime host-virtual consistence is not necessary.
So options come
 host first docker run -v hostDir1:/virtualDir1:cached  
 virtual first docker run -v hostDir1:/virtualDir1:delegated
 realTime run -v hostDir1:/virtualDir1:consistent 

docker run exec

「docker run」コマンドは、コンテナを作成して起動するコマンド。
docker run  -it image_name "/bin/bash"
他のTabでdocker ps
Containerが増える。
実質は:
     docker create image_name
    docker start image_name


「docker exec」コマンドは、起動中のコンテナ内で、指定したコマンドを実行するコマンド。
docker ps
docker exec -it container_id "/bin/bash"




docker-run options image_name init_command
-- name (起動されたContainerに名前)
-- rm (Container終了時削除)
-v  fromHostSrc:toContainerTarget-e   env parameters
-d  run in backend

docker-sync start サンプル:
docker run --rm -v "dir1:/app_sync" -v "dir2:/host_sync" -e HOST_VOLUME=/host_sync -e APP_VOLUME=/app_sync -e TZ=$(basename $(dirname `readlink /etc/localtime`))/$(basename `readlink /etc/localtime`) -e UNISON_SRC="/host_sync" -e UNISON_DEST="/app_sync" -e UNISON_ARGS=" -ignore='Name .git' -ignore='Name .idea' -ignore='Name mysql_data' -prefer /host_sync -numericids -auto -batch" -e UNISON_WATCH_ARGS="-repeat watch"  --name backend-service eugenmayer/unison:2.51.2.1 /usr/local/bin/precopy_appsync

試しに一回起動してすぐ削除されたので、また起動
docker run -d -v "dir1:/app_sync" -v "dir2:/host_sync" -e HOST_VOLUME=/host_sync -e APP_VOLUME=/app_sync -e TZ=$(basename $(dirname `readlink /etc/localtime`))/$(basename `readlink /etc/localtime`) -e UNISON_SRC="/host_sync" -e UNISON_DEST="/app_sync" -e UNISON_ARGS=" -ignore='Name .git' -ignore='Name .idea' -ignore='Name mysql_data' -prefer /host_sync -numericids -auto -batch" -e UNISON_WATCH_ARGS="-repeat watch"  --name backend-service eugenmayer/unison:2.51.2.1



2019/12/20

wechat miniapp login


  • wechat miniApp:  wx.login -> code
  • wechat miniApp: wx.request , send code to server api
  • server request 
    • wechat API,get openId and sesion_key: https://api.weixin.qq.com/sns/jscode2session?appid=a&secret=b&js_code=codegrant_type=authorization_code
    • use openId and session_key to generate access token
    • response access token and openId to miniAPP(token1)
  • wechat miniApp: wx.getSetting check user's authority.if not ,request user's authority.
  • wechat miniApp: wx.getUserInfo can get user info.
  • server request wechat api to get token(token2) :
    • https://api.weixin.qq.com/cgi-bin/token?appid=a&secret=b&grant_type=client_credential
  • server request wetchat api use token 

docker show all container ,delete all



  • docker show all container :     docker container ls -a
  • docker show volume:   docker volume ls 
  • docker show image: docker image ls
  • delete all unused objects:        docker system prune -f --volumes
  • delete all images:  docker image prune -a
  • docker-compose up -d  --remove-orphans
スキリした。普通に30Gぐらい削除した。unusedの基準は曖昧かな


2019/12/18

golang gorm update when record not exist

when record is not exist. update will be success.
have to check RowsAffected .
the same as delte

query := db.Model(r).Updates(something)
if query.Error != nil {
   return query.Error
}
if query.RowsAffected == 0 {
   return gorm.ErrRecordNotFound
}



query := db.Delete(&something{ID: ID})
if query.Error != nil {
   return query.Error
}
if query.RowsAffected == 0 {
   return gorm.ErrRecordNotFound
}

2019/12/16

MacOS bad support on HFS/APFS

 MacOS/OSX has very bad filesystem events support on HFS/APFS, watching the file-system for changes using unox or fswatch was causing a heavy CPU load. This CPU load is very significant, even on modern high-end CPUs (like a i7 4770k / 3.5GHz).