當前位置: 首頁>>代碼示例>>Golang>>正文


Golang IPermissions.UserState方法代碼示例

本文整理匯總了Golang中github.com/xyproto/pinterface.IPermissions.UserState方法的典型用法代碼示例。如果您正苦於以下問題:Golang IPermissions.UserState方法的具體用法?Golang IPermissions.UserState怎麽用?Golang IPermissions.UserState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/xyproto/pinterface.IPermissions的用法示例。


在下文中一共展示了IPermissions.UserState方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: runConfiguration

// Run a Lua file as a configuration script. Also has access to the userstate and permissions.
// Returns an error if there was a problem with running the lua script, otherwise nil.
func runConfiguration(filename string, perm pinterface.IPermissions, luapool *lStatePool, cache *FileCache, mux *http.ServeMux, singleFileMode bool) error {

	// Retrieve a Lua state
	L := luapool.Get()

	// Retrieve the userstate
	userstate := perm.UserState()

	// Server configuration functions
	exportServerConfigFunctions(L, perm, filename, luapool)

	// Other basic system functions, like log()
	exportBasicSystemFunctions(L)

	// Simpleredis data structures (could be used for storing server stats)
	exportList(L, userstate)
	exportSet(L, userstate)
	exportHash(L, userstate)
	exportKeyValue(L, userstate)

	// For handling JSON data
	exportJSONFunctions(L)
	exportJFile(L, filepath.Dir(filename))

	// For saving and loading Lua functions
	exportCodeLibrary(L, userstate)

	// Plugins
	exportPluginFunctions(L, nil)

	// Cache
	exportCacheFunctions(L, cache)

	if singleFileMode {
		// Lua HTTP handlers
		exportLuaHandlerFunctions(L, filename, perm, luapool, cache, mux, false)
	}

	// Run the script
	if err := L.DoFile(filename); err != nil {
		// Close the Lua state
		L.Close()

		// Logging and/or HTTP response is handled elsewhere
		return err
	}

	// Only put the Lua state back if there were no errors
	luapool.Put(L)

	return nil
}
開發者ID:jeraldrich,項目名稱:algernon,代碼行數:54,代碼來源:lua.go

示例2: exportCommonFunctions

// Return a *lua.LState object that contains several exposed functions
func exportCommonFunctions(w http.ResponseWriter, req *http.Request, filename string, perm pinterface.IPermissions, L *lua.LState, luapool *lStatePool, flushFunc func(), cache *FileCache) {

	// Retrieve the userstate
	userstate := perm.UserState()

	// Make basic functions, like print, available to the Lua script.
	// Only exports functions that can relate to HTTP responses or requests.
	exportBasicWeb(w, req, L, filename, flushFunc)

	// Functions for serving files in the same directory as a script
	exportServeFile(w, req, L, filename, perm, luapool, cache)

	// Make other basic functions available
	exportBasicSystemFunctions(L)

	// Functions for rendering markdown or amber
	exportRenderFunctions(w, req, L)

	// Make the functions related to userstate available to the Lua script
	exportUserstate(w, req, L, userstate)

	// Simpleredis data structures
	exportList(L, userstate)
	exportSet(L, userstate)
	exportHash(L, userstate)
	exportKeyValue(L, userstate)

	// For handling JSON data
	exportJSONFunctions(L)
	exportJFile(L, filepath.Dir(filename))

	// For saving and loading Lua functions
	exportCodeLibrary(L, userstate)

	// pprint
	//exportREPL(L)

	// Plugins
	exportPluginFunctions(L, nil)

	// Cache
	exportCacheFunctions(L, cache)

	// File uploads
	exportUploadedFile(L, w, req, filepath.Dir(filename))
}
開發者ID:jeraldrich,項目名稱:algernon,代碼行數:47,代碼來源:lua.go

示例3: REPL

// REPL provides a "Read Eveal Print" loop for interacting with Lua.
// A variety of functions are exposed to the Lua state.
func REPL(perm pinterface.IPermissions, luapool *lStatePool, cache *FileCache, ready, done chan bool) error {
	var (
		historyFilename string
		err             error
	)

	historydir, err := homedir.Dir()
	if err != nil {
		log.Error("Could not find a user directory to store the REPL history.")
		historydir = "."
	}
	if runtime.GOOS == "windows" {
		historyFilename = filepath.Join(historydir, "algernon", "repl.txt")
	} else {
		historyFilename = filepath.Join(historydir, ".algernon_history")
	}

	// Retrieve the userstate
	userstate := perm.UserState()

	// Retrieve a Lua state
	L := luapool.Get()
	// Don't re-use the Lua state
	defer L.Close()

	// Server configuration functions
	exportServerConfigFunctions(L, perm, "", luapool)

	// Other basic system functions, like log()
	exportBasicSystemFunctions(L)

	// Simpleredis data structures
	exportList(L, userstate)
	exportSet(L, userstate)
	exportHash(L, userstate)
	exportKeyValue(L, userstate)

	// For handling JSON data
	exportJSONFunctions(L)
	exportJFile(L, serverDir)

	// For saving and loading Lua functions
	exportCodeLibrary(L, userstate)

	// Pretty printing
	exportREPL(L)

	// Colors and input
	enableColors := runtime.GOOS != "windows"
	o := term.NewTextOutput(enableColors, true)

	// Plugin functionality
	exportPluginFunctions(L, o)

	// Cache
	exportCacheFunctions(L, cache)

	// Getting ready
	o.Println(o.LightBlue(versionString))

	<-ready // Wait for the server to be ready

	// Tell the user that the server is ready
	o.Println(o.LightGreen("Ready"))

	// Start the read, eval, print loop
	var (
		line     string
		prompt   = o.LightGreen("lua> ")
		EOF      bool
		EOFcount int
	)
	if loadHistory(historyFilename) != nil && fs.exists(historyFilename) {
		log.Error("Could not load REPL history:", historyFilename)
	}
	// To be run at server shutdown
	atShutdown(func() {
		// Verbose mode has different log output at shutdown
		if !verboseMode {
			o.Println(o.LightBlue(exitMessage))
		}
	})
	for {
		// Retrieve user input
		EOF = false
		if line, err = getInput(prompt); err != nil {
			if err.Error() == "EOF" {
				if debugMode {
					o.Println(o.LightPurple(err.Error()))
				}
				EOF = true
			} else {
				log.Error("Error reading line(" + err.Error() + ").")
				continue
			}
		} else {
			addHistory(line)
			// Save the REPL history at every line.
//.........這裏部分代碼省略.........
開發者ID:sneakyweasel,項目名稱:algernon,代碼行數:101,代碼來源:repl.go


注:本文中的github.com/xyproto/pinterface.IPermissions.UserState方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。