小改造gotty,使之適合接收通過一層加密的URL

固然,比起密碼設置,這個安全性也不是特別高,html

但比起直接傳參數。git

仍是要專業一些的。github

其實現思路分兩種:golang

第一種是在gotty.js以內加入解url的函數。shell

第二種在是go源代碼時,加入同等的解密函數。安全

哈,第一種快,只要懂js。app

第二種要懂go。函數

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~url

但,就算是第一種,你覺得,只要更改resources目錄下的gotty.js就能夠了麼?code

否!!!這裏只是一個js的原文件,而gotty的實現思路,是將resources下的資源文件,

經過一個叫go-bindata的東東,

把靜態文件封裝到go的源文件中來實現文件打包,並經過統一的接口來調用。

不信的話,看與app.go平行的resource.go文件前幾行:

// Code generated by go-bindata.
// sources:
// bindata/static/favicon.png
// bindata/static/index.html
// bindata/static/js/gotty.js
// bindata/static/js/hterm.js
// DO NOT EDIT!

package app

import (
	"bytes"
	"compress/gzip"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"time"
)

func bindataRead(data []byte, name string) ([]byte, error) {
	gz, err := gzip.NewReader(bytes.NewBuffer(data))
	if err != nil {
		return nil, fmt.Errorf("Read %q: %v", name, err)
	}

	var buf bytes.Buffer
	_, err = io.Copy(&buf, gz)
	clErr := gz.Close()

	if err != nil {
		return nil, fmt.Errorf("Read %q: %v", name, err)
	}
	if clErr != nil {
		return nil, err
	}

	return buf.Bytes(), nil
}

type asset struct {
	bytes []byte
	info  os.FileInfo
}

type bindataFileInfo struct {
	name    string
	size    int64
	mode    os.FileMode
	modTime time.Time
}

func (fi bindataFileInfo) Name() string {
	return fi.name
}
func (fi bindataFileInfo) Size() int64 {
	return fi.size
}
func (fi bindataFileInfo) Mode() os.FileMode {
	return fi.mode
}
func (fi bindataFileInfo) ModTime() time.Time {
	return fi.modTime
}
func (fi bindataFileInfo) IsDir() bool {
	return false
}
func (fi bindataFileInfo) Sys() interface{} {
	return nil
}

  

so,爲了向gotty.js中加入幾行,我得先改gotty.js裏的文件,

而後,經過go-bindata將這個js文件更新到代碼中。

https://www.b612.me/golang/103.html

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

go-bindata經過把靜態文件封裝到go的源文件中來實現文件打包,並經過統一的接口來調用

 

安裝

go get github.com/jteeuwen/go-bindata/...
go get github.com/elazarl/go-bindata-assetfs/...
go install
 

使用

go-bindata  -pkg main -o data/bindata.go data/

上述命令便能把data中文件打包爲bindata.go
或下述命令

go-bindata-assetfs data/...

使用相對路徑得到文件數據

datas, err := Asset("data/someting")
相關文章
相關標籤/搜索