gin 使用 pack2 打包 html到二进制

直接上我的一个web播放器的样例代码片段

主要是 LoadTemplate 方法

然后打包的时候需要用packr2工具:

#安装编译工具,用于打包html到二进制
go get -u github.com/gobuffalo/packr/v2/packr2
#build和go build一样,交叉编译的方式也是一样的
CGO_ENABLED=0 GOOS=linux GOARCH=arm packr2 build  -o 115_player
#简单点的
packr2 build  -o 115_player

 

代码片段: 浏览全部

PHP、golang 如何播放mp4文件

php的处理过程

<?php
function PutMovie(file) {
    header("Content-type: video/mp4");
    header("Accept-Ranges: bytes");size = filesize(file);
    if(isset(_SERVER['HTTP_RANGE'])){
        header("HTTP/1.1 206 Partial Content");
        list(name,range) = explode("=", _SERVER['HTTP_RANGE']);
        list(begin, end) =explode("-",range);
        if(end == 0)end = size - 1;
    }
    else {begin = 0; end =size - 1;
    }
    header("Content-Length: " . (end -begin + 1));
    header("Content-Disposition: filename=".basename(file));
    header("Content-Range: bytes ".begin."-".end."/".size);
 
    fp = fopen(file, 'rb');
    fseek(fp,begin);
    while(!feof(fp)) {p = min(1024, end -begin + 1);
        begin +=p;
        echo fread(fp,p);
    }
    fclose($fp);
}
PutMovie("1.mp4");

golang的处理过程

http.ServeFile(w, r, "/webserver/1.mp4")

 

Docker CE 镜像源站 linux 下国内源安装 阿里源

使用官方脚本:

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

 

Ubuntu 14.04 16.04 (使用apt-get进行安装)

# step 1: 安装必要的一些系统工具
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# step 2: 安装GPG证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# Step 3: 写入软件源信息
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# Step 4: 更新并安装 Docker-CE
sudo apt-get -y update
sudo apt-get -y install docker-ce

CentOS 7 (使用yum进行安装)

# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3: 更新并安装 Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce
# Step 4: 开启Docker服务
sudo service docker start

 

mac下开发 github 上传大于 50M的文件 git-lfs

Homebrewbrew install git-lfs
MacPortsport install git-lfs

1、安装git和git-lfs,然后运行:

`git lfs install`

2、添加你要上传的大文件例如:

git lfs track "*.psd"

确保.gitattributes is tracked:

git add .gitattributes

3、开始推送:

git add file.psd
git commit -m "Add design file"
git push origin master

参考网站:https://git-lfs.github.com/

mac上遇到的错误sed command a expects followed by text

mac上简单的替换操作

sed -i 's/apple/mac/g' full-path-file
执行后报错,“sed: 1: command a expects \ followed by text”
由于mac系统与linux系统下sed用法的差异,下面给出两种解决方案
(差异可自己在两个系统用man命令查看帮助)
第一种解决方案

sed命令改写为

sed -i '' 's/apple/mac/g' full-path-file
第二种解决方案调整macsed的用法,使其与linux一致
mac上安装gnu-sed
brew install gnu-sed
alias sed=gsed

调整后两系统下sed的用法完全一致。

注意添加PATH=/usr/local/opt/gnu-sed/libexec/gnubin:/$PATH

白嫖 unas的 frp服务

前言:

unas的 uanywhere服务是基于frp的,而且是privilege模式的。因此,只要有了privilege_token和服务ip以及端口,那么就能白嫖各种服务啦~

流程:

  1. 最好是安装一下最新的unas包,登录一下uanywhere,更新下配置。
  2. `cat /etc/uanywhere/frpc.ini`,即可获取到最新的frpc.ini配置。(其他tcp/udp的穿透不确定能不能用,穿透http和https就好了)
  3. 修改一下,配合自己的域名,做好域名cname到www.myunas.com。
  4. 启动你自己的frpc服务。

浏览全部