utils

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2019 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SSH_IO_MODE_CHANNEL = 0
	SSH_IO_MODE_SESSION = 1
)

Variables

View Source
var Config struct {
	Site struct {
		AppName    string `yaml:"app_name"`
		RunMode    string `yaml:"runmode"`
		DeployHost string `yaml:"deploy_host"`
		ListenAddr string `yaml:"listen_addr"`
	} `yaml:"site"`
	Prod struct {
		StaticPrefix string `yaml:"static_prefix"` // http prefix of static and views files
	} `yaml:"prod"`
	Dev struct {
		StaticPrefix string `yaml:"static_prefix"` // https prefix of only static files
		//StaticPrefix string `yaml:"static_prefix"` // prefix of static files in dev mode.
		// redirect static files requests to this address, redirect "StaticPrefix" to "StaticRedirect + StaticPrefix"
		// for example, StaticPrefix is "static", StaticRedirect is "localhost:8080/dist",
		// this will redirect all requests having prefix "static" to "localhost:8080/dist/"
		StaticRedirect string `yaml:"static_redirect"`
		// http server will read static file from this dir if StaticRedirect is empty
		StaticDir   string `yaml:"static_dir"`
		ViewsPrefix string `yaml:"views_prefix"` // https prefix of only views files
		// path of view files (we can not redirect view files) to be served.
		ViewsDir string `yaml:"views_dir"` // todo
	} `yaml:"dev"`
	SSH struct {
		BufferCheckerCycleTime int `yaml:"buffer_checker_cycle_time"`
	} `yaml:"ssh"`
	Jwt struct {
		Secret        string `yaml:"jwt_secret"`
		TokenLifetime int64  `yaml:"token_lifetime"`
		Issuer        string `yaml:"issuer"`
		QueryTokenKey string `yaml:"query_token_key"`
	} `yaml:"jwt"`
}
View Source
var NotFound = http.NotFound

NotFound is called when no asset is found. It defaults to http.NotFound but can be overwritten

Server is simply ServeHTTP but wrapped in http.HandlerFunc so it can be passed into net/http functions directly.

Functions

func Abort

func Abort(w http.ResponseWriter, message string, code int)

func GetQueryInt

func GetQueryInt(r *http.Request, key string, defaultValue int) int

func GetQueryInt32

func GetQueryInt32(r *http.Request, key string, defaultValue uint32) uint32

func Hash

func Hash(file string) (s string)

Hash returns the hex-encoded SHA256 hash of the original file Used for the Etag, and useful for caching Returns an empty string if the file is not in the bundle

func InitConfig added in v0.2.0

func InitConfig(filepath string) error

func JwtNewToken

func JwtNewToken(connection Connection, issuer string) (tokenString string, expire int64, err error)

create a jwt token,and return this token as string type.

func MemStatic added in v0.2.0

func MemStatic(staticDir string)

read all files in views directory and map to "staticFiles"

func ModTime

func ModTime(file string) (t time.Time)

ModTime returns the modification time of the original file. Useful for caching purposes Returns zero time if the file is not in the bundle

func Open

func Open(name string) (io.ReadCloser, error)

Open allows you to read an embedded file directly. It will return a decompressing Reader if the file is embedded in compressed format. You should close the Reader after you're done with it.

func ServeHTTP

func ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP serves a request, attempting to reply with an embedded file.

func ServeJSON

func ServeJSON(w http.ResponseWriter, j interface{})

Types

type Claims

type Claims struct {
	Connection
	jwt.StandardClaims
}

func JwtVerify

func JwtVerify(tokenString string) (*Claims, error)

Verify a jwt token

type Connection

type Connection Node // struct alias.

type Node

type Node struct {
	Host string // host, e.g: ssh.example.com
	Port int    //port,default value is 22
	// contains filtered or unexported fields
}

func (*Node) Connect

func (node *Node) Connect(username, password string) error

see: http://www.nljb.net/default/Go-SSH-%E4%BD%BF%E7%94%A8/ establish a ssh connection. if success return nil, than can operate ssh connection via pointer SSH.client in struct SSH.

func (*Node) GetClient

func (node *Node) GetClient() (*ssh.Client, error)

type SSHConnInterface

type SSHConnInterface interface {
	// close ssh connection
	Close()
	// connect using username and password
	Connect(username, password string) error
	// config connection after connected
	Config(cols, rows uint32) error
}

type SSHShellChannel

type SSHShellChannel struct {
	Node
	Channel ssh.Channel
}

deprecated, use session SSHShellSession instead connect to ssh server using channel.

func (*SSHShellChannel) Config

func (ch *SSHShellChannel) Config(cols, rows uint32) error

type SSHShellSession

type SSHShellSession struct {
	Node
	// calling Write() to write data to ssh server
	StdinPipe io.WriteCloser
	// Write() be called to receive data from ssh server
	WriterPipe io.Writer
	Session    *ssh.Session
}

connect to ssh server using ssh session.

func (*SSHShellSession) Close

func (s *SSHShellSession) Close()

func (*SSHShellSession) Config

func (s *SSHShellSession) Config(cols, rows uint32) error

setup ssh shell session set Session and StdinPipe here, and the Session.Stdout and Session.Sdterr are also set.

type Session

type Session struct {
	Value interface{}
	// contains filtered or unexported fields
}

type SessionManager

type SessionManager struct {
	// contains filtered or unexported fields
}

use jwt string as session key, store user information(username and password) in Session.

var SessionStorage SessionManager

func (*SessionManager) Delete

func (s *SessionManager) Delete(key string)

func (*SessionManager) Get

func (s *SessionManager) Get(key string) (sessionData Session, exist bool)

func (*SessionManager) Put

func (s *SessionManager) Put(key string, expire int64, value interface{})

* * add a new session to session manager. * @params:token: token string * expire: unix time for expire * password: ssh user password

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL