-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from mutablelogic/v4
Scope updates
- Loading branch information
Showing
9 changed files
with
168 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package nginx | ||
|
||
import ( | ||
// Packages | ||
"github.com/mutablelogic/go-server/pkg/version" | ||
) | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// GLOBALS | ||
|
||
var ( | ||
// Prefix | ||
scopePrefix = version.GitSource + "/scope/" | ||
) | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// PUBLIC METHODS | ||
|
||
func (nginx *nginx) ScopeRead() []string { | ||
// Return read (list, get) scopes | ||
return []string{ | ||
scopePrefix + nginx.Label() + "/read", | ||
scopePrefix + defaultName + "/read", | ||
} | ||
} | ||
|
||
func (nginx *nginx) ScopeWrite() []string { | ||
// Return write (create, delete, update) scopes | ||
return []string{ | ||
scopePrefix + nginx.Label() + "/write", | ||
scopePrefix + defaultName + "/write", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package router | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"regexp" | ||
|
||
// Packages | ||
server "github.com/mutablelogic/go-server" | ||
httpresponse "github.com/mutablelogic/go-server/pkg/httpresponse" | ||
) | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// GLOBALS | ||
|
||
const ( | ||
jsonIndent = 2 | ||
) | ||
|
||
var ( | ||
reRoot = regexp.MustCompile(`^/?$`) | ||
) | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// PUBLIC METHODS - ENDPOINTS | ||
|
||
// Add endpoints to the router | ||
func (service *router) AddEndpoints(ctx context.Context, r server.Router) { | ||
// Path: / | ||
// Methods: GET | ||
// Scopes: read | ||
// Description: Get router services | ||
r.AddHandlerFuncRe(ctx, reRoot, service.GetScopes, http.MethodGet).(Route). | ||
SetScope(service.ScopeRead()...) | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// PUBLIC METHODS | ||
|
||
// Get registered scopes | ||
func (service *router) GetScopes(w http.ResponseWriter, r *http.Request) { | ||
httpresponse.JSON(w, service.Scopes(), http.StatusOK, jsonIndent) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package router | ||
|
||
import ( | ||
// Packages | ||
"github.com/mutablelogic/go-server/pkg/version" | ||
) | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// GLOBALS | ||
|
||
var ( | ||
// Prefix | ||
scopePrefix = version.GitSource + "/scope/" | ||
) | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// PUBLIC METHODS | ||
|
||
func (router *router) ScopeRead() []string { | ||
// Return read (list, get) scopes | ||
return []string{ | ||
scopePrefix + router.Label() + "/read", | ||
scopePrefix + defaultName + "/read", | ||
} | ||
} | ||
|
||
func (router *router) ScopeWrite() []string { | ||
// Return write (create, delete, update) scopes | ||
return []string{ | ||
scopePrefix + router.Label() + "/write", | ||
scopePrefix + defaultName + "/write", | ||
} | ||
} |