mirror of
https://github.com/gomods/athens
synced 2026-02-08 11:18:10 +00:00
* Added filter for private repos. Non private repos get redirected to olympus * Changed filter to allow private modules * Changed config file name function * Added filter tests * The middleware returns 200 for privates, redirects public, 404 for disabled repos * Removed printf * Removed forgotten printf * Removed logger from the middleware func, not used anymore * Removed unused (uncommented) function * Replaced 404 with 403 in case of banned modules * Fixed test path / cleaned olympus endpoint suffix * Added error operation to GetVersion * Moved filter test in custom file, reverted injection of the filter into the app * Removed white line * Clarified comment for ignoring getversion error * Added todo comment to fill the cache and serve the request with the cache * Added error handling to filter * Removed commented early version of the test
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package paths
|
|
|
|
import (
|
|
"github.com/gobuffalo/buffalo"
|
|
"github.com/gomods/athens/pkg/errors"
|
|
)
|
|
|
|
// GetModule gets the module from the path of a ?go-get=1 request
|
|
func GetModule(c buffalo.Context) (string, error) {
|
|
const op errors.Op = "paths.GetModule"
|
|
|
|
module := c.Param("module")
|
|
if module == "" {
|
|
return "", errors.E(op, "missing module parameter")
|
|
}
|
|
|
|
return DecodePath(module)
|
|
}
|
|
|
|
// GetVersion gets the version from the path of a ?go-get=1 request
|
|
func GetVersion(c buffalo.Context) (string, error) {
|
|
const op errors.Op = "paths.GetVersion"
|
|
|
|
version := c.Param("version")
|
|
if version == "" {
|
|
return "", errors.E(op, "missing version paramater")
|
|
}
|
|
return version, nil
|
|
}
|
|
|
|
// AllPathParams holds the module and version in the path of a ?go-get=1
|
|
// request
|
|
type AllPathParams struct {
|
|
Module string
|
|
Version string
|
|
}
|
|
|
|
// GetAllParams fetches the path patams from c and returns them
|
|
func GetAllParams(c buffalo.Context) (*AllPathParams, error) {
|
|
const op errors.Op = "paths.GetAllParams"
|
|
mod, err := GetModule(c)
|
|
if err != nil {
|
|
return nil, errors.E(op, err)
|
|
}
|
|
|
|
version, err := GetVersion(c)
|
|
if err != nil {
|
|
return nil, errors.E(op, err)
|
|
}
|
|
|
|
return &AllPathParams{Module: mod, Version: version}, nil
|
|
}
|