webserver

package
v0.0.0-...-0b5a9a0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileExists

func FileExists(filePath string) bool

func GetUserRealIP

func GetUserRealIP(r *http.Request) string

GetUserRealIP Get User Real IP from headers of request `r`

  1. First, determine whether the remote addr of request is a private address. If it is a public network address, return it directly;
  2. Otherwise, get and check the real IP from X-REAL-IP and X-Forwarded-For headers in turn. if the header value contains multiple IP addresses separated by commas, that is, the request may pass through multiple reverse proxies, we just keep the first one, which imply it is the user connecting IP. then we check the value is a valid public IP address using the `IsIPValidAndPublic` function. If it is, the function returns the value as the client's real IP address.
  3. Finally, If the above headers do not exist or are invalid, the remote addr is returned as is.

func IsIPValidAndPublic

func IsIPValidAndPublic(ipAddr string) bool

IsIPValidAndPublic is a helper function check if an IP address is valid and public.

func IsPrivateIP

func IsPrivateIP(ip net.IP) bool

IsPrivateIP check IPv4 or IPv6 address according to the length of byte array

Types

type Config

type Config struct {
	DB            database.DB
	DataDir       string
	ServerAddress string
	ServerPort    int
	RootPath      string
	Log           bool
}

Config is parameter that used for starting web server

type Handler

type Handler struct {
	DB           database.DB
	DataDir      string
	RootPath     string
	UserCache    *cch.Cache
	SessionCache *cch.Cache
	ArchiveCache *cch.Cache
	Log          bool
	// contains filtered or unexported fields
}

Handler is Handler for serving the web interface.

func GetLegacyHandler

func GetLegacyHandler(cfg Config, dependencies *dependencies.Dependencies) *Handler

func (*Handler) ApiDeleteAccount

func (h *Handler) ApiDeleteAccount(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

ApiDeleteAccount is handler for DELETE /api/accounts

func (*Handler) ApiDeleteBookmark

func (h *Handler) ApiDeleteBookmark(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

ApiDeleteBookmarks is handler for DELETE /api/bookmark

func (*Handler) ApiDeleteViaExtension

func (h *Handler) ApiDeleteViaExtension(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

ApiDeleteViaExtension is handler for DELETE /api/bookmark/ext

func (*Handler) ApiGetAccounts

func (h *Handler) ApiGetAccounts(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

ApiGetAccounts is handler for GET /api/accounts

func (*Handler) ApiGetBookmarks

func (h *Handler) ApiGetBookmarks(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

ApiGetBookmarks is handler for GET /api/bookmarks

func (*Handler) ApiGetTags

func (h *Handler) ApiGetTags(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

ApiGetTags is handler for GET /api/tags

func (*Handler) ApiInsertAccount

func (h *Handler) ApiInsertAccount(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

ApiInsertAccount is handler for POST /api/accounts

func (*Handler) ApiInsertBookmark

func (h *Handler) ApiInsertBookmark(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

ApiInsertBookmark is handler for POST /api/bookmark

func (*Handler) ApiInsertViaExtension

func (h *Handler) ApiInsertViaExtension(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

ApiInsertViaExtension is handler for POST /api/bookmarks/ext

func (*Handler) ApiLogout

func (h *Handler) ApiLogout(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

ApiLogout is handler for POST /api/logout

func (*Handler) ApiRenameTag

func (h *Handler) ApiRenameTag(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

ApiRenameTag is handler for PUT /api/tag

func (*Handler) ApiUpdateAccount

func (h *Handler) ApiUpdateAccount(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

ApiUpdateAccount is handler for PUT /api/accounts

func (*Handler) ApiUpdateBookmark

func (h *Handler) ApiUpdateBookmark(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

ApiUpdateBookmark is handler for PUT /api/bookmarks

func (*Handler) ApiUpdateBookmarkTags

func (h *Handler) ApiUpdateBookmarkTags(w http.ResponseWriter, r *http.Request, ps httprouter.Params)

ApiUpdateBookmarkTags is handler for PUT /api/bookmarks/tags

func (*Handler) GetSessionID

func (h *Handler) GetSessionID(r *http.Request) string

func (*Handler) PrepareSessionCache

func (h *Handler) PrepareSessionCache()

func (*Handler) PrepareTemplates

func (h *Handler) PrepareTemplates() error

Jump to

Keyboard shortcuts

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