server

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

README

Server

API List

Name Route Method Remark
Navigation Page / GET
Login Page /login/index GET
User Sign In API /signin POST
Source File Server /source/ GET
DestPath File Server /dest/ GET
File Query API /query GET
PProf API /debug/pprof GET
File Query API

Support query source or dest path from File Server.

Method

GET

Parameter
  • path query file path, for example path=source
  • need_hash return file hash or not, 1 or 0, default is 0
Response

For example:

http://127.0.0.1/query?path=source&need_hash=1

Response field description:

  • code status code,0 means success
  • message response status description
  • data response data
  • path file path
  • is_dir is directory or not, 1 or 0
  • size file size of bytes, directory is always 0
  • hash return file hash value if set need_hash=1
  • c_time file create time
  • a_time file last access time
  • m_time file last modify time

An example response for query api.

{
	"code": 0,
	"message": "success",
	"data": [{
		"path": "hello-gofs.txt",
		"is_dir": 0,
		"size": 11,
		"hash": "5eb63bbbe01eeed093cb22bb8f5acdc3",
		"c_time": 1642731076,
		"a_time": 1642731088,
		"m_time": 1642731088
	}, {
		"path": "resource",
		"is_dir": 1,
		"size": 0,
		"hash": "",
		"c_time": 1642731096,
		"a_time": 1642731102,
		"m_time": 1642731102
	}]
}

Documentation

Index

Constants

View Source
const (
	// ParamUserName the parameter name of username
	ParamUserName = "username"
	// ParamPassword the parameter name of password
	ParamPassword = "password"
	// ParamReturnUrl the parameter name of return url
	ParamReturnUrl = "return_url"
)
View Source
const (
	// SourceRoutePrefix the route prefix of source
	SourceRoutePrefix = "/source/"
	// DestRoutePrefix the route prefix of dest
	DestRoutePrefix = "/dest/"
	// QueryRoute the route of query api
	QueryRoute = "/query"
	// LoginGroupRoute the group route of login
	LoginGroupRoute = "/login"
	// LoginIndexRoute the route of login index page
	LoginIndexRoute = "/index"
	// LoginIndexFullRoute the full route of login index page
	LoginIndexFullRoute = LoginGroupRoute + LoginIndexRoute
	// LoginSignInRoute the route of sign in api
	LoginSignInRoute = "/signin"
	// LoginSignInFullRoute the full route of sign in api
	LoginSignInFullRoute = LoginGroupRoute + LoginSignInRoute
	// WriteGroupRoute the group route of write api
	WriteGroupRoute = "/w"
	// PushRoute the route of push api
	PushRoute = "/push"
	// PushFullRoute the full route of push api
	PushFullRoute = WriteGroupRoute + PushRoute
)
View Source
const (
	// DefaultAddrHttps the default https address
	DefaultAddrHttps = ":443"
	// DefaultAddrHttp the default http address
	DefaultAddrHttp = ":80"
	// SchemeHttp the http scheme name
	SchemeHttp = "http"
	// SchemeHttps the https scheme name
	SchemeHttps = "https"
	// DefaultPortHttp the default port of http server
	DefaultPortHttp = 80
	// DefaultPortHttps the default port of https server
	DefaultPortHttps = 443
)
View Source
const (
	// SessionName the name of the session
	SessionName = "session_id"
	// SessionUser the key of the session user
	SessionUser = "user"
)
View Source
const (
	// ResourceTemplatePath the web server template resource path
	ResourceTemplatePath = "server/template/*"
)

Variables

This section is empty.

Functions

func Addr added in v0.2.4

func Addr() *net.TCPAddr

Addr the addr of file server running

func DefaultSessionStore

func DefaultSessionStore() (sessions.Store, error)

DefaultSessionStore create a default session store, current is stored in memory

func EnableTLS

func EnableTLS() bool

EnableTLS is using https on the file server

func GenerateAddr

func GenerateAddr(scheme, host string, port int) string

GenerateAddr generate http or https address

func InitServerInfo

func InitServerInfo(addr string, tls bool)

InitServerInfo int the file web server

func Port added in v0.2.4

func Port() int

Port the port of file server running

func PrintAnonymousAccessWarning

func PrintAnonymousAccessWarning()

PrintAnonymousAccessWarning print the warning log of anonymous access

Types

type ApiResult

type ApiResult struct {
	Code    contract.Code `json:"code"`
	Message string        `json:"message"`
	Data    interface{}   `json:"data"`
}

ApiResult the common result of api response

func NewApiResult

func NewApiResult(code contract.Code, message string, data interface{}) ApiResult

NewApiResult create an instance of the ApiResult

func NewErrorApiResult

func NewErrorApiResult(code contract.Code, message string) ApiResult

NewErrorApiResult create an instance of the ApiResult that contains error info

func NewServerErrorResult added in v0.3.0

func NewServerErrorResult() ApiResult

NewServerErrorResult create an instance of the ApiResult that means server error

type Option

type Option struct {
	Source                core.VFS
	Dest                  core.VFS
	Addr                  string
	Init                  wait.WaitDone
	EnableTLS             bool
	CertFile              string
	KeyFile               string
	Users                 []*auth.User
	EnableCompress        bool
	Logger                log.Logger
	EnablePprof           bool
	PprofPrivate          bool
	EnableLogicallyDelete bool
	EnablePushServer      bool
}

Option the web server option

func NewServerOption

func NewServerOption(config conf.Config, init wait.WaitDone, users []*auth.User, logger log.Logger) Option

NewServerOption create an instance of the Option, store all the web server options

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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