Documentation

Overview

    Package api contains the REST API for RUFS.

    /about

    Endpoint which returns an object with version information.

    {

    api_versions : List of available API versions e.g. [ "v1" ]
    product      : Name of the API provider (RUFS)
    version:     : Version of the API provider
    

    }

    Index

    Constants

    View Source
    const APIRoot = "/fs"

      APIRoot is the API root directory for the REST API

      View Source
      const APIVersion = "1.0.0"

        APIVersion is the version of the REST API

        View Source
        const EndpointAbout = APIRoot + "/about/"

          EndpointAbout is the about endpoint definition (rooted). Handles about/

          View Source
          const EndpointSwagger = APIRoot + "/swagger.json/"

            EndpointSwagger is the swagger endpoint URL (rooted). Handles swagger.json/

            Variables

            View Source
            var APIHost = "localhost:9040"

              APIHost is the host definition for the REST API

              View Source
              var APISchemes = []string{"https"}

                APISchemes defines the supported schemes by the REST API

                View Source
                var AddTree = func(id string, tree *rufs.Tree) error {
                	treesLock.Lock()
                	defer treesLock.Unlock()
                
                	if _, ok := trees[id]; ok {
                		return fmt.Errorf("Tree %v already exists", id)
                	}
                
                	trees[id] = tree
                
                	return nil
                }

                  AddTree adds a new tree. This function can be overwritten by client code to implement access control.

                  View Source
                  var GeneralEndpointMap = map[string]RestEndpointInst{
                  	EndpointAbout:   AboutEndpointInst,
                  	EndpointSwagger: SwaggerEndpointInst,
                  }

                    GeneralEndpointMap is a map of urls to general REST endpoints

                    View Source
                    var GetTree = func(id string) (*rufs.Tree, bool, error) {
                    	treesLock.Lock()
                    	defer treesLock.Unlock()
                    
                    	tree, ok := trees[id]
                    
                    	return tree, ok, nil
                    }

                      GetTree returns a specific tree. This function can be overwritten by client code to implement access control.

                      View Source
                      var HandleFunc = http.HandleFunc

                        HandleFunc to use for registering handlers

                        View Source
                        var RemoveTree = func(id string) error {
                        	treesLock.Lock()
                        	defer treesLock.Unlock()
                        
                        	if _, ok := trees[id]; !ok {
                        		return fmt.Errorf("Tree %v does not exist", id)
                        	}
                        
                        	delete(trees, id)
                        
                        	return nil
                        }

                          RemoveTree removes a tree. This function can be overwritten by client code to implement access control.

                          View Source
                          var ResetTrees = func() {
                          	treesLock.Lock()
                          	defer treesLock.Unlock()
                          
                          	trees = make(map[string]*rufs.Tree)
                          }

                            ResetTrees removes all registered trees.

                            View Source
                            var TreeCertTemplate *tls.Certificate

                              TreeCertTemplate is the certificate which is used for newly created trees.

                              View Source
                              var TreeConfigTemplate map[string]interface{}

                                TreeConfigTemplate is the configuration which is used for newly created trees.

                                View Source
                                var Trees = func() (map[string]*rufs.Tree, error) {
                                	treesLock.Lock()
                                	defer treesLock.Unlock()
                                
                                	ret := make(map[string]*rufs.Tree)
                                
                                	for k, v := range trees {
                                		ret[k] = v
                                	}
                                
                                	return ret, nil
                                }

                                  Trees is a getter function which returns a map of all registered trees. This function can be overwritten by client code to implement access control.

                                  Functions

                                  func RegisterRestEndpoints

                                  func RegisterRestEndpoints(endpointInsts map[string]RestEndpointInst)

                                    RegisterRestEndpoints registers all given REST endpoint handlers.

                                    Types

                                    type DefaultEndpointHandler

                                    type DefaultEndpointHandler struct {
                                    }

                                      DefaultEndpointHandler is the default endpoint handler implementation.

                                      func (*DefaultEndpointHandler) HandleDELETE

                                      func (de *DefaultEndpointHandler) HandleDELETE(w http.ResponseWriter, r *http.Request, resources []string)

                                        HandleDELETE handles a DELETE request.

                                        func (*DefaultEndpointHandler) HandleGET

                                        func (de *DefaultEndpointHandler) HandleGET(w http.ResponseWriter, r *http.Request, resources []string)

                                          HandleGET handles a GET request.

                                          func (*DefaultEndpointHandler) HandlePOST

                                          func (de *DefaultEndpointHandler) HandlePOST(w http.ResponseWriter, r *http.Request, resources []string)

                                            HandlePOST handles a POST request.

                                            func (*DefaultEndpointHandler) HandlePUT

                                            func (de *DefaultEndpointHandler) HandlePUT(w http.ResponseWriter, r *http.Request, resources []string)

                                              HandlePUT handles a PUT request.

                                              type RestEndpointHandler

                                              type RestEndpointHandler interface {
                                              
                                              	/*
                                              		HandleGET handles a GET request.
                                              	*/
                                              	HandleGET(w http.ResponseWriter, r *http.Request, resources []string)
                                              
                                              	/*
                                              		HandlePOST handles a POST request.
                                              	*/
                                              	HandlePOST(w http.ResponseWriter, r *http.Request, resources []string)
                                              
                                              	/*
                                              		HandlePUT handles a PUT request.
                                              	*/
                                              	HandlePUT(w http.ResponseWriter, r *http.Request, resources []string)
                                              
                                              	/*
                                              		HandleDELETE handles a DELETE request.
                                              	*/
                                              	HandleDELETE(w http.ResponseWriter, r *http.Request, resources []string)
                                              
                                              	/*
                                              		SwaggerDefs is used to describe the endpoint in swagger.
                                              	*/
                                              	SwaggerDefs(s map[string]interface{})
                                              }

                                                RestEndpointHandler models a REST endpoint handler.

                                                func AboutEndpointInst

                                                func AboutEndpointInst() RestEndpointHandler

                                                  AboutEndpointInst creates a new endpoint handler.

                                                  func SwaggerEndpointInst

                                                  func SwaggerEndpointInst() RestEndpointHandler

                                                    SwaggerEndpointInst creates a new endpoint handler.

                                                    type RestEndpointInst

                                                    type RestEndpointInst func() RestEndpointHandler

                                                      RestEndpointInst models a factory function for REST endpoint handlers.

                                                      Directories

                                                      Path Synopsis
                                                      Package v1 contains Rufs REST API Version 1.
                                                      Package v1 contains Rufs REST API Version 1.