Skip to content

Commit

Permalink
chore: add golang-ci linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Salaton committed Jan 11, 2023
1 parent 10d9b9a commit b73ad91
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
41 changes: 41 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Options for analysis running.
run:
linters:
disable-all: true
enable:
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
- asciicheck
- bodyclose
- dogsled
- exhaustive
- exportloopref
- gocognit
- goconst
- gofmt
- goheader
- goimports
- gosec
- misspell
- nakedret
- nestif
- noctx
- rowserrcheck
- sqlclosecheck
- unconvert
- unparam
- whitespace
- gocyclo
- golint

linters-settings:
staticcheck:
checks: ["all"]
10 changes: 5 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Client struct {
// Config holds the necessary authentication configurations for interacting with the casdoor service
type Config struct {
CasdoorEndpoint string `json:"endpoint"`
ClientId string `json:"client_id"`
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
CasdoorOrganization string `json:"organization"`
CasdoorApplication string `json:"application"`
Expand Down Expand Up @@ -57,7 +57,7 @@ func NewClient(config Config) (*Client, error) {
client: &http.Client{},
configurations: Config{
CasdoorEndpoint: config.CasdoorEndpoint,
ClientId: config.ClientId,
ClientID: config.ClientID,
ClientSecret: config.ClientSecret,
CasdoorOrganization: config.CasdoorOrganization,
CasdoorApplication: config.CasdoorApplication,
Expand All @@ -66,7 +66,7 @@ func NewClient(config Config) (*Client, error) {

casdoorsdk.InitConfig(
config.CasdoorEndpoint,
config.ClientId,
config.ClientID,
config.ClientSecret,
config.Certificate,
config.CasdoorOrganization,
Expand Down Expand Up @@ -99,7 +99,7 @@ func (c *Client) makeRequest(
}

if isAuthorized {
req.SetBasicAuth(c.configurations.ClientId, c.configurations.ClientSecret)
req.SetBasicAuth(c.configurations.ClientID, c.configurations.ClientSecret)
}

req.Header.Set("Accept", "application/json")
Expand All @@ -119,7 +119,7 @@ func (c *Client) Login(ctx context.Context, username, password string) (*LoginRe
loginEndpoint := fmt.Sprintf("%s/api/login/oauth/access_token", c.configurations.CasdoorEndpoint)
payload := LoginPayload{
GrantType: "password",
ClientID: c.configurations.ClientId,
ClientID: c.configurations.ClientID,
ClientSecret: c.configurations.ClientSecret,
Username: username,
Password: password,
Expand Down
3 changes: 3 additions & 0 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ type authCheckFn = func(
r *http.Request,
) (bool, map[string]string, *TokenIntrospectionResponse)

// CasdoorAuthenticationMiddleware is responsible for validating user's authentication credentials before allowing access to protected routes.
// It uses the provided authentication service to check the user's token
// and ensure it is valid and has the necessary permissions for the requested resource
func CasdoorAuthenticationMiddleware(c Client) func(http.Handler) http.Handler {
// multiple checks will be run in sequence (order matters)
// the first check to succeed will call `c.Next()` and `return`
Expand Down

0 comments on commit b73ad91

Please sign in to comment.