utils

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: MIT Imports: 23 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
		ApiPrefix    string `yaml:"api_prefix"`
	} `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.
		ApiPrefix string `yaml:"api_prefix"`

		// 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/static/"
		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 ForkSftpClient added in v0.2.2

func ForkSftpClient(key string) *sftp.Client

make a copy of SftpEntity matched with given key. return sftp.client pointer or nil pointer.

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 Join added in v0.2.2

func Join(key string, sftpEntity SftpEntity)

add a sftp client to subscribers list.

func JwtNewToken

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

create a jwt token,and return this token as string type. we can create a new token with Claims in it if login is successful. then, we can known the host and port when setting up websocket or sftp.

func Leave added in v0.2.2

func Leave(key string)

remove a sftp client by key.

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 {
	JwtConnection
	jwt.StandardClaims
}

func JwtVerify

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

Verify a jwt token

type JwtConnection added in v0.2.2

type JwtConnection struct {
	Host string
	Port int
}

payload in jwt

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 NewSSHNode added in v0.2.2

func NewSSHNode(host string, port int) Node

func (*Node) Connect

func (node *Node) Connect(username string, auth ssh.AuthMethod) 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 Node.client in struct Node.

func (*Node) GetClient

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

type SSHConnInterface

type SSHConnInterface interface {
	// close ssh connection
	Close() error
	// connect using username and password
	Connect(username string, auth ssh.AuthMethod) error
	// config connection after connected and may also create a ssh session.
	Config(cols, rows uint32) (*ssh.Session, 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
	// contains filtered or unexported fields
}

connect to ssh server using ssh session.

func (*SSHShellSession) Close

func (s *SSHShellSession) Close() error

func (*SSHShellSession) Config

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

setup ssh shell session set SSHShellSession.session and StdinPipe from created session here. and Session.Stdout and Session.Stderr are also set for outputting. Return value is a pointer of ssh session which is created by ssh client for shell interaction. If it has error in this func, ssh session will be nil.

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

type SftpEntity added in v0.2.2

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

func Fork added in v0.2.2

func Fork(key string) (SftpEntity, bool)

make a copy of SftpEntity matched with given key. return sftpEntity and exist flag (bool).

func NewSftpEntity added in v0.2.2

func NewSftpEntity(user SftpNode, username string, auth ssh.AuthMethod) (SftpEntity, error)

func (*SftpEntity) Close added in v0.2.2

func (con *SftpEntity) Close() error

close sftp session and ssh client

type SftpNode added in v0.2.2

type SftpNode Node // struct alias.

Jump to

Keyboard shortcuts

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