Documentation ¶
Overview ¶
Package server provides an Http interface to Rscs.
Example ¶
// You need a sqlite file. We assume here that you have one with // a pre-existing `kv` table, if not, look at rscs.go in this directory // for an example of how to create an empty one. var sqliteDBFile string flag.StringVar(&sqliteDBFile, "db", "", "full path to sqlite db file") flag.Parse() if sqliteDBFile == "" { log.Fatal(`use: example_daemon --db={sqlite db file}`) } // Create a DB instance for sqlite. rscsDB, rscsDBErr := db.NewRscsDB(sqliteDBFile) if rscsDBErr != nil { log.Fatal(rscsDBErr) } // Create an http abstraction layer. rscsServer, rscsSrvErr := NewRscsServer(rscsDB) if rscsSrvErr != nil { log.Fatal(rscsSrvErr) } // Instantiate a router. rtr, rtrErr := rscsServer.NewRouter() if rtrErr != nil { log.Fatal(rtrErr.Error()) } // Listen. srv := &http.Server{Addr: ":8081", Handler: rtr} log.Fatal(srv.ListenAndServe())
Output:
Index ¶
- Constants
- type ContextKeyType
- type RscsServer
- func (s *RscsServer) Delete(w http.ResponseWriter, r *http.Request)
- func (s *RscsServer) Get(w http.ResponseWriter, r *http.Request)
- func (s *RscsServer) Insert(w http.ResponseWriter, r *http.Request)
- func (s *RscsServer) NewRouter() (*chi.Mux, error)
- func (s *RscsServer) Status(w http.ResponseWriter, r *http.Request)
- func (s *RscsServer) Update(w http.ResponseWriter, r *http.Request)
- type StatusResult
- type Value
Examples ¶
Constants ¶
View Source
const ( // KVRoutePrefix is the prefix for the kv route. KVRoutePrefix = "/v1/kv" // KVRoute is the route for all key/val operations. KVRoute = KVRoutePrefix + "/:key" // StatusRoute is the route for system status. StatusRoute = "/v1/status" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContextKeyType ¶
type ContextKeyType int
ContextKeyType is the type used to reference values in the Context.
type RscsServer ¶
type RscsServer struct {
// contains filtered or unexported fields
}
RscsServer contains the state values for the underlying database instance and for https routing.
func NewRscsServer ¶
func NewRscsServer(rscsDB *db.RscsDB) (*RscsServer, error)
NewRscsServer initializes a new RscsServer instance.
func (*RscsServer) Delete ¶
func (s *RscsServer) Delete(w http.ResponseWriter, r *http.Request)
Delete removes a row identified by a key.
func (*RscsServer) Get ¶
func (s *RscsServer) Get(w http.ResponseWriter, r *http.Request)
Get retrieves the value for the key passed on the URL path.
func (*RscsServer) Insert ¶
func (s *RscsServer) Insert(w http.ResponseWriter, r *http.Request)
Insert adds a new key/value pair.
func (*RscsServer) NewRouter ¶
func (s *RscsServer) NewRouter() (*chi.Mux, error)
NewRouter provides a new chi router to pass to a server.
func (*RscsServer) Status ¶
func (s *RscsServer) Status(w http.ResponseWriter, r *http.Request)
Status returns the system status as JSON.
func (*RscsServer) Update ¶
func (s *RscsServer) Update(w http.ResponseWriter, r *http.Request)
Update changes the value of an existing key/value pair.
type StatusResult ¶
StatusResult describes the system status.
Source Files ¶
Click to show internal directories.
Click to hide internal directories.