fileserve

package
v0.7.10 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CommandLocationMap map[string]string // xyzzyInit - Command set map of commands to full paths
View Source
var ErrInputFileMissing = errors.New("Unable to find file that was avaialbe earlier in processing.")
View Source
var ErrOutputFileError = errors.New("Output error")
View Source
var ExtProcessTable []*ExtProcessType
View Source
var InternalFuncLookup map[string]InternalFuncTableType // xyzzyInit - Lookup of functions for ExtProcessType table

Functions

func CheckETag

func CheckETag(www http.ResponseWriter, req *http.Request, modtime time.Time) (rangeReq string, done bool)

============================================================================================================================================ CheckETag implements If-None-Match and If-Range checks.

The ETag or modtime must have been previously set in the http.ResponseWriter's headers. The modtime is only compared at second granularity and may be the zero value to mean unknown.

The return value is the effective request "Range" header to use and whether this request is now considered done.

func CheckLastModified

func CheckLastModified(www http.ResponseWriter, req *http.Request, modtime time.Time) bool

============================================================================================================================================ modtime is the modification time of the resource to be served, or IsZero(). return value is whether this request is now complete.

func ConvMakrdown

func ConvMakrdown(in, out string) (err error)

func ExecuteCommands

func ExecuteCommands(CommandToRun string, inputFile, outputFile, inExt, outExt string) (ok bool, outString string, errString string)

ok, errString := ExecuteCommands(tr.CommandToRun) need to make this a "worker" and only run 1 at a time of this.,, All others wait pending!

func ExecuteCommandsMulti

func ExecuteCommandsMulti(CommandToRun string, inputFile []string, outputFile string, inExt []string, outExt string) (ok bool, outString string, errString string)

func GenLockKey

func GenLockKey(s0 string, s ...string) (rv string)

func GetRwHdlrFromWWW_2

func GetRwHdlrFromWWW_2(www http.ResponseWriter, req *http.Request) (rw *goftlmux.MidBuffer, ok bool)

============================================================================================================================================

func InitNLogged

func InitNLogged()

func LockCmd

func LockCmd(aKey string)

func LogErrors

func LogErrors(fcfg *FileServerType, www http.ResponseWriter, req *http.Request, s string)

func LogOutputAsSuccess

func LogOutputAsSuccess(fcfg *FileServerType, www http.ResponseWriter, req *http.Request, s string)

func OutputErrors

func OutputErrors(fcfg *FileServerType, www http.ResponseWriter, req *http.Request, s string)

func RmExt

func RmExt(filename string) string

func RmExtSpecified

func RmExtSpecified(filename, extension string) string

Remove the specified extension from the file name. If the extension is the entire file name then return an empty stirng.

func ServeFile

func ServeFile(w http.ResponseWriter, r *http.Request, name string)

============================================================================================================================================

func UnLockCmd

func UnLockCmd(aKey string)

Types

type ACommandToRun

type ACommandToRun struct {
	Cmd    string
	Params []string
}

type Dir

type Dir string

func (Dir) Open

func (d Dir) Open(name string) (File, error)

type ExLockType

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

type ExtProcessType

type ExtProcessType struct {
	ToExt            []string         `json:"ToExt"`        //	Set of output extensions
	FromExt          string           `json:"FromExt"`      // Input extension
	HasFs            string           `json:"HasFs"`        // File sep
	CommandToRun     string           `json:"CommandToRun"` // typescript {{.f_base}}.ts
	ReRun            bool             `json:"ReRun"`        // if false(default) then check timestamps on input->output, else just run every time		-- xyzzy not implemented yet?
	InternalFunc     InternalFuncType `json:"-"`            // if true then if InternalFunc != nil, then call it.
	InternalFuncName string           `json:"InternalFunc"` // string name to lookkup InteralFunc by
}

type FSConfig

type FSConfig struct {
	Name                    string
	IndexPage               []string // list of paths for IndexPage
	MayShowDirectoryListing bool

	// -----------------------------------------------------------------------------------------------------------
	PreMangle bool // Process ULR before - this is like strip prefix
	PreRule   []PreRuleType
}

Pre-Rules Post-Rules Data-Avail-Rules

func NewFSConfig

func NewFSConfig(s string) *FSConfig

func (*FSConfig) AddPreRule

func (g *FSConfig) AddPreRule(r []PreRuleType) *FSConfig

func (*FSConfig) DirectoryListings

func (g *FSConfig) DirectoryListings(b bool) *FSConfig

func (*FSConfig) IndexHTML

func (g *FSConfig) IndexHTML(s string) *FSConfig

type File

type File interface {
	io.Closer
	io.Reader
	Readdir(count int) ([]os.FileInfo, error)
	Seek(offset int64, whence int) (int64, error)
	Stat() (os.FileInfo, error)
}

A File is returned by a FileSystem's Open method and can be served by the FileServer implementation.

The methods should behave the same as those on an *os.File.

type FileServerType

type FileServerType struct {
	Next               http.Handler // No Next, this is the bottom of the stack.
	Paths              []string
	Root               []string
	StripPrefix        string
	IndexFileList      []string
	ThemeRoot          string
	ThemeCookieName    string
	UserCookieName     string
	LineNo             int
	Cfg                *FSConfig         // Runtime configuration for servring and finding files.
	SampleNumber       int               // xyzzy - not implemented yet
	SamplePattern      string            // xyzzy - not implemented yet
	CommandLocationMap map[string]string // xyzzyInit - Command set map of commands to full paths
	ExtProcessTable    []*ExtProcessType
}

func NewFileServer

func NewFileServer(n http.Handler, g *FSConfig, Path []string, IndexFileList []string, Root []string) *FileServerType

func (*FileServerType) InitializeWithConfigData

func (hdlr *FileServerType) InitializeWithConfigData(next http.Handler, gCfg *cfg.ServerGlobalConfigType, serverName string, pNo, callNo int) (err error)

func (*FileServerType) PreValidate

func (hdlr *FileServerType) PreValidate(gCfg *cfg.ServerGlobalConfigType, cfgData map[string]interface{}, serverName string, pNo, callNo int) (err error)

func (*FileServerType) ServeFile

func (fcfg *FileServerType) ServeFile(www http.ResponseWriter, req *http.Request, name string)

============================================================================================================================================

1. Transform extensions

.md->.html
.sccs->.css
.ts->.js

f: [ .ext ], t [ .out, .other ]		If request .other, and have .ext then run command and build
									If request .ext and have .other, then if out of date rebuild

[

{ "f": ".js", "t": [ ".min.js", ".min.map" ],    "cmd": "uglifyjs --input {{.f}} --output {{.t}} --generate-mapfile" }

, { "f": ".ts", "t": [ ".js" ], "cmd": "typescirpt {{.f}} " } , { "f": ".css", "t": [ ".min.css" ], "cmd": "pack-css --in {{.f}} --out {{.t}}" } ]

name is '/'-separated, not filepath.Separator. fs contains the directory name, name is the file name.

func (*FileServerType) ServeHTTP

func (fcfg *FileServerType) ServeHTTP(www http.ResponseWriter, req *http.Request)

type FileSystem

type FileSystem interface {
	Open(name string) (File, error)
}

A FileSystem implements access to a collection of named files. The elements in a file path are separated by slash ('/', U+002F) characters, regardless of host operating system convention.

type InternalFuncTableType

type InternalFuncTableType struct {
	InternalFunc     InternalFuncType `json:"-"`            // if true then if InternalFunc != nil, then call it.
	InternalFuncName string           `json:"InternalFunc"` // string name to lookkup InteralFunc by
}

type InternalFuncType

type InternalFuncType func(input, output string) (err error)

type PreRuleType

type PreRuleType struct {
	IfMatch       string        //
	StripPrefix   string        //
	UseRoot       string        //
	StatusOnMatch RuleStatus    //
	Fx            UrlModifyFunc //
	MatchData     interface{}   //
	IfFromSuffix  string        // From suffix .ts
	IfToSuffix    []string      // To .js
	CommandToRun  string        // typescript {{.f_base}}.ts
	ReRun         bool          // if false(default) then check timestamps on input->output, else just run every time
}

type RebuildFlag

type RebuildFlag int
const (
	NeedRebuild       RebuildFlag = 1
	TimestampsInOrder RebuildFlag = 2
)

func CompareModTime

func CompareModTime(in, out time.Time) RebuildFlag

return true if modification time for in is after out

func (RebuildFlag) String

func (nr RebuildFlag) String() string

type RuleStatus

type RuleStatus int
const (
	PreSuccess RuleStatus = iota // Use this result - it matched.
	PreFail                      // Fail all results, return 404
	PreNext                      // Do not use this, proceed to next, if no next then 404
	PreReplace                   // Function  returns new root and or new name for file
)

func ResolveFnThemeUser

func ResolveFnThemeUser(fcfg *FileServerType, www http.ResponseWriter, req *http.Request, urlIn string, g *FSConfig, rulNo int) (urlOut string, rootOut string, stat RuleStatus, err error)

func UrlFileExt

func UrlFileExt(fcfg *FileServerType, www http.ResponseWriter, req *http.Request, urlIn string, g *FSConfig, rulNo int) (urlOut string, rootOut string, stat RuleStatus, err error)

func (RuleStatus) String

func (rs RuleStatus) String() string

type UrlModifyFunc

type UrlModifyFunc func(fcfg *FileServerType, www http.ResponseWriter, req *http.Request, urlIn string, g *FSConfig, rulNo int) (urlOut string, rootOut string, stat RuleStatus, err error)

Jump to

Keyboard shortcuts

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