Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spelling, grammar, typos and minor Go fixes #30

Merged
merged 17 commits into from
Jan 4, 2024
3 changes: 2 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
String registryEndpoint = 'registry.comp.ystv.co.uk'

def branch = env.BRANCH_NAME.replaceAll("/", "_")
def image
String imageName = "ystv/web-api:${env.BRANCH_NAME}-${env.BUILD_ID}"
String imageName = "ystv/web-api:${branch}-${env.BUILD_ID}"

pipeline {
agent {
Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# YSTV web-api

A Go based backend that should be able to handle website queries? Hopefully having a supportive subroutine to keep everything in order. Designed kind of like a monolith, but we'll see where we get to with it.
A Go-based backend that should be able to handle website queries?
Hopefully having a supportive subroutine to keep everything in order.
Designed kind of like a monolith, but we'll see where we get to with it.

Generation of usable JWT's is available in [web-auth](https://github.com/ystv/web-auth) currently.

Expand Down Expand Up @@ -38,8 +40,8 @@ Generation of usable JWT's is available in [web-auth](https://github.com/ystv/we
- [x] List meta
- [x] Create meta
- [x] Update meta
- [ ] Create video list
- [ ] Update video list
- [ ] Create a video list
- [ ] Update a video list
- [ ] Encoding
- [ ] Presets
- [x] Get
Expand Down Expand Up @@ -94,7 +96,7 @@ Generation of usable JWT's is available in [web-auth](https://github.com/ystv/we
## Dependencies

- Go (For developing only)
- A database (Although, it might be hardcoded for postgres?)
- A database (although it might be hardcoded for postgres?)
- A "CDN", I just mean a connection to an S3 like interface.
- AMQP compatible broker i.e. RabbitMQ.

Expand All @@ -121,7 +123,7 @@ Run `./web-api` and hopefully it should be running.

Unlike the static binary this uses docker's environment variables instead of a `.env` file. The API's port will be exposed on port `8080`.

To start either method you will need to clone the repo.
To start either method, you will need to clone the repo.

`git clone https://github.com/ystv/web-api`

Expand Down Expand Up @@ -152,7 +154,7 @@ Developed on Go version 1.14+

Clone the repo and create a `.env.local` for an easy config setup. Use the `debug` flag to disable auth.

I recommend not using the production environment for testing and recommend running postgres and rabbitmq in Docker.
I recommend not using the production environment for testing and recommending running postgres and rabbitmq in Docker.

Updating the DB schema use `goose` to migrate safely.

Expand All @@ -173,7 +175,7 @@ Generate docs by running `go generate` in the root of the repo.
- `/docs`
echo-swagger autogenerated docs.
- `/middleware`
REST middleware, implements some URL sanitization and logging.
REST middleware, implements some URL sanitisation and logging.
- `/routes`
Handles how the REST api is arranged and applies extra middleware if necessary.
- `/services`
Expand All @@ -183,4 +185,6 @@ Generate docs by running `go generate` in the root of the repo.

### Database info

This is currently build using the new schema available in the [planning repo](https://github.com/ystv/Website2ElectricBoogaloo), it is still lacking functionality compared to the current implementation.
This is currently built
using the new schema available in the [planning repo](https://github.com/ystv/Website2ElectricBoogaloo),
it is still lacking functionality compared to the current implementation.
8 changes: 5 additions & 3 deletions architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ This document aims to assist developers on understanding the codebase.

This application follows the MVC architecture (sort of) at a high level.
With the `controllers` packages containing the code handling HTTP responses
and putting it into something Go can handle. The services packages are
where all the business logic is contained. Each package has a set domain.
and putting it into something Go can handle.
The service packages are
where all the business logic is contained.
Each package has a set domain.

The current aim with the services package is to have a set of core packages:
The current aim with the service package is to have a set of core packages:
* vod (handling all Video on Demand queries)
* campus (campus related activities)

Expand Down
8 changes: 4 additions & 4 deletions ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

We use Jenkins at YSTV to automate our build deployments. For each of our website 2020's repos we've included a `Jenkinsfile` which will allow you to replicate your own build environment like ours.

We use multi-stage pipelines and would recommend them for best compatibility with our scripts.
We use multi-stage pipelines and would recommend them for the best compatibility with our scripts.

The repo should be mostly plug and play with Jenkins, but you will need to set a couple of credentials that are used by all of our pipelines:

- `docker-registry-endpoint` (secret text) - A Docker registry endpoint i.e. `registry.ystv.co.uk`, checkout this [guide](https://docs.docker.com/registry/) to learn more.
- `docker-registry-endpoint` (secret text) - A Docker registry endpoint i.e. `registry.ystv.co.uk`, check out this [guide](https://docs.docker.com/registry/) to learn more.

- `staging-server-address` (secret text) - Either an IP address or host name of a server running docker to SSH to
- `staging-server-path` (secret text) - The folder path of where all applications are stored i.e. `/opt`.
- `staging-server-key` (SSH Username with private key) - A SSH key which will allow authentication to the staging server. Generate with `ssh-keygen`.
- `staging-server-key` (SSH Username with a private key) - A SSH key which will allow authentication to the staging server. Generate with `ssh-keygen`.

- `prod-server-address` (secret text) - Either an IP address or host name of a server running docker to SSH to.
- `prod-server-path` (secret text) - The folder path of where all applications are stored i.e. `/opt`.
- `prod-server-key` (SSH Username with private key) - A SSH key which will allow authentication to the staging server. Generate with `ssh-keygen`.
- `prod-server-key` (SSH Username with a private key) - A SSH key which will allow authentication to the staging server. Generate with `ssh-keygen`.

Credentials specific to web-api

Expand Down
2 changes: 1 addition & 1 deletion configs/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ services:
- WAPI_DOMAIN_NAME=

- WAPI_BUCKET_VOD_SERVE=
- WAPI_BUKCET_VOD_INGEST=
- WAPI_BUCKET_VOD_INGEST=

# JWT Signing key
- WAPI_SIGNING_KEY=
Expand Down
2 changes: 1 addition & 1 deletion controllers/v1/clapper/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (r *Repos) NewEvent(c echo.Context) error {

// UpdateEvent updates an existing event
// @Summary Update event
// @Description updates an event. Only uses the meta, if you change the
// @Description updates an event. Only use the meta, if you change the
// @Description type it will delete the children.
// @ID update-event
// @Tags clapper-events
Expand Down
2 changes: 1 addition & 1 deletion controllers/v1/clapper/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (r *Repos) UpdatePosition(c echo.Context) error {
func (r *Repos) DeletePosition(c echo.Context) error {
positionID, err := strconv.Atoi(c.Param("positionid"))
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid posiiton ID")
return echo.NewHTTPError(http.StatusBadRequest, "Invalid position ID")
}
err = r.position.Delete(c.Request().Context(), positionID)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions controllers/v1/clapper/signup.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// NewSignup handles a creating a signup sheet
//
// @Summary New signup sheet
// @Description Creates a new signup sheet, this is the sub part of an event
// @Description Creates a new signup sheet; this is the subpart of an event
// @Description containing the list of crew, with a little metadata on top.
// @ID new-signup
// @Tags clapper-signups
Expand Down Expand Up @@ -46,7 +46,7 @@ func (r *Repos) NewSignup(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

// Insert new signup sheet
// Insert a new signup sheet
signupID, err := r.signup.New(c.Request().Context(), e.EventID, s)
if err != nil {
err = fmt.Errorf("NewSignup: failed to insert new signup: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion controllers/v1/creator/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewRepos(db *sqlx.DB, cdn *s3.S3, enc *encoder.Encoder, access *utils.Acces
}
}

// Stats handles sending general stats about the video library
// Stats handle sending general stats about the video library
// @Summary Get global video library information
// @Description Gets the statistics about the global video library.
// @ID get-creator-glob-stats
Expand Down
2 changes: 1 addition & 1 deletion controllers/v1/creator/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (r *Repos) NewEncodePreset(c echo.Context) error {

// UpdateEncodePreset handles updating a preset
// @Summary Update a preset
// @Description updates an preset
// @Description updates a preset
// @ID update-creator-encode-preset
// @Tags creator-encodes
// @Accept json
Expand Down
2 changes: 1 addition & 1 deletion controllers/v1/creator/playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ystv/web-api/services/creator/types/playlist"
)

// ListPlaylist handles listing all playlist metadata's
// ListPlaylist handles listing all playlist metadata
// @Summary List all playlists
// @Description Lists all playlists, doesn't include videos inside.
// @ID get-creator-playlists-all
Expand Down
5 changes: 3 additions & 2 deletions controllers/v1/creator/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ func (r *Repos) VideoList(c echo.Context) error {
// ListVideosByUser Handles retrieving a user's videos using their userid in their token.
//
// @Summary List all videos created by user ID
// @Description Lists all videos, doesn't include files inside. Uses the createdBy user ID.
// @Description Lists all videos, doesn't include files inside.
// Use the createdBy user ID.
// @ID get-creator-videos-user
// @Tags creator-videos
// @Produce json
Expand Down Expand Up @@ -178,7 +179,7 @@ type searchInput struct {
Query string `json:"query"`
}

// SearchVideo Handles listing appropriate videos from a relevant search
// SearchVideo Handles listing appropriate videos from the relevant search
//
// @Summary Search videos
// @Description Search videos.
Expand Down
4 changes: 2 additions & 2 deletions controllers/v1/encoder/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func NewEncoderController(enc *encoder.Encoder, access *utils.Accesser) *Repo {
// UploadRequest handles authenticating an upload request.
//
// Connects with tusd through web-hooks, so tusd POSTs here.
// tusd's requests here does contain a lot of useful information.
// but for this endpoint, we are just checking for the JWT.
// Tusd's requests here do contain a lot of useful information.
// But for this endpoint, we are just checking for the JWT.
//
// @Summary New upload request
// @Description Authenticates tusd's webhook requests
Expand Down
32 changes: 16 additions & 16 deletions controllers/v1/misc/webcam.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func (r *Repos) ListWebcams(c echo.Context) error {
// @Description Reverse proxies the selected webcam returns the jpeg feed as a result.
// @ID get-webcam
// @Tags misc-webcams
// @Param cameraid path int true "Camera ID"
// @Router /v1/internal/misc/webcams/{cameraid} [get]
// @Param cameraID path int true "Camera ID"
// @Router /v1/internal/misc/webcams/{cameraID} [get]
func (r *Repos) GetWebcam(c echo.Context) error {
cameraID, err := strconv.Atoi(c.Param("id"))
if err != nil {
Expand Down Expand Up @@ -96,35 +96,35 @@ func (r *Repos) GetWebcam(c echo.Context) error {
}

func singleJoiningSlash(a, b string) string {
aslash := strings.HasSuffix(a, "/")
bslash := strings.HasPrefix(b, "/")
aSlash := strings.HasSuffix(a, "/")
bSlash := strings.HasPrefix(b, "/")
switch {
case aslash && bslash:
case aSlash && bSlash:
return a + b[1:]
case !aslash && !bslash:
case !aSlash && !bSlash:
return a + "/" + b
}
return a + b
}

func joinURLPath(proxy, req *url.URL) (path, rawpath string) {
func joinURLPath(proxy, req *url.URL) (path, rawPath string) {
req.Path = strings.TrimSuffix(req.Path, proxy.Path)
if proxy.RawPath == "" && req.RawPath == "" {
return singleJoiningSlash(proxy.Path, req.Path), ""
}
// Same as singleJoiningSlash, but uses EscapedPath to determine
// whether a slash should be added
apath := proxy.EscapedPath()
bpath := req.EscapedPath()
aPath := proxy.EscapedPath()
bPath := req.EscapedPath()

aslash := strings.HasSuffix(apath, "/")
bslash := strings.HasPrefix(bpath, "/")
aSlash := strings.HasSuffix(aPath, "/")
bSlash := strings.HasPrefix(bPath, "/")

switch {
case aslash && bslash:
return proxy.Path + req.Path[1:], apath + bpath[1:]
case !aslash && !bslash:
return proxy.Path + "/" + req.Path, apath + "/" + bpath
case aSlash && bSlash:
return proxy.Path + req.Path[1:], aPath + bPath[1:]
case !aSlash && !bSlash:
return proxy.Path + "/" + req.Path, aPath + "/" + bPath
}
return proxy.Path + req.Path, apath + bpath
return proxy.Path + req.Path, aPath + bPath
}
2 changes: 1 addition & 1 deletion controllers/v1/people/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (r *Repo) UserByID(c echo.Context) error {
return c.JSON(http.StatusOK, p)
}

// UserByIDFull finds a user by ID returing all info
// UserByIDFull finds a user by ID returning all info
// @Summary Get a full user by ID
// @Description Get a complete user object by ID.
// @ID get-user-id-full
Expand Down
2 changes: 1 addition & 1 deletion controllers/v1/public/breadcrumb.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/ystv/web-api/services/public"
)

// Find handles converting a url path to either a video or series
// Find handles converting an url path to either a video or series
//
// @Summary Converts a VOD url to either a series or video
// @Description Allows us to remain backwards compatible with the existing URLs
Expand Down
2 changes: 1 addition & 1 deletion controllers/v1/public/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// ListChannels handles listing all channels
//
// @Summary Provides the visible channels
// @Description Lists the publically visible channels
// @Description Lists the publicly visible channels
// @ID get-public-stream-channels
// @Tags public-playout-channels
// @Produce json
Expand Down
8 changes: 4 additions & 4 deletions controllers/v1/public/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ func (r *Repos) GetTeamById(c echo.Context) error {
// @Success 200 {object} public.Team
// @Router /v1/public/teams/email/{emailAlias}/{year} [get]
func (r *Repos) GetTeamByYearByEmail(c echo.Context) error {
//teamID, err := strconv.Atoi(c.Param("teamid"))
//fmt.Println(teamID)
//if err != nil {
// teamID, err := strconv.Atoi(c.Param("teamid"))
// fmt.Println(teamID)
// if err != nil {
// return echo.NewHTTPError(http.StatusBadRequest, "Bad teamid")
//}
// }
year, err := strconv.Atoi(c.Param("year"))
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Bad year")
Expand Down
2 changes: 1 addition & 1 deletion controllers/v1/public/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/labstack/echo/v4"
)

// Video handles a video item, providing info vfiles
// Video handles a video item, providing info
//
// @Summary Provides a video item
// @Description Returns a video item. Including the video files.
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/ystv/web-api/controllers/v1/misc"
"github.com/ystv/web-api/controllers/v1/people"
"github.com/ystv/web-api/controllers/v1/public"
"github.com/ystv/web-api/routes"
"github.com/ystv/web-api/services/encoder"

"github.com/ystv/web-api/utils"
Expand Down Expand Up @@ -105,7 +104,7 @@ func main() {
}
enc := encoder.NewEncoder(db, cdn, encoderConfig)

routes.New(&routes.NewRouter{
New(&NewRouter{
Version: Version,
Commit: Commit,
DomainName: os.Getenv("WAPI_DOMAIN_NAME"),
Expand Down
5 changes: 2 additions & 3 deletions middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"
"strings"

"github.com/labstack/echo-contrib/prometheus"
"github.com/labstack/echo-contrib/echoprometheus"
"github.com/labstack/echo/v4"
echoMw "github.com/labstack/echo/v4/middleware"
)
Expand Down Expand Up @@ -49,6 +49,5 @@ func New(e *echo.Echo, domainName string) {
}))
// TODO secure this
// /metrics, view using curl
p := prometheus.NewPrometheus("echo", nil)
p.Use(e)
e.Use(echoprometheus.NewMiddleware("echo"))
}
Loading