Skip to content

Commit

Permalink
✨ api config
Browse files Browse the repository at this point in the history
  • Loading branch information
perebaj committed Aug 13, 2023
1 parent e7c34ba commit 31a073a
Show file tree
Hide file tree
Showing 6 changed files with 313 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GOLANGCI_LINT_VERSION=v1.54.0

# configuration/aliases
version=$(shell git rev-parse --short HEAD)
base_image=us-central1-docker.pkg.dev/birdie-org/birdie/jj/armoco
base_image=perebaj/armoco
image=$(base_image):$(version)
devimage=armoco-dev
# To avoid downloading deps everytime it runs on containers
Expand Down
36 changes: 36 additions & 0 deletions api/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package api

import (
"embed"
"net/http"

"github.com/go-openapi/runtime/middleware"
"github.com/gorilla/mux"
"golang.org/x/exp/slog"
)

func handlePostImage(w http.ResponseWriter, r *http.Request) {
slog.Info("handlePostImage")

}

func handleGetImage(w http.ResponseWriter, r *http.Request) {
slog.Info("handleGetImage")

}

//go:embed openapi.yaml
var swaggerFs embed.FS

func Routes() *mux.Router {
router := mux.NewRouter()
router.HandleFunc("/v1/images", handlePostImage).Methods("POST")
router.HandleFunc("/v1/images", handleGetImage).Methods("GET")

opts := middleware.SwaggerUIOpts{SpecURL: "openapi.yaml"}
sh := middleware.SwaggerUI(opts, nil)
router.Handle("/docs", sh)
router.Handle("/openapi.yaml", http.FileServer(http.FS(swaggerFs)))
return router

}
59 changes: 59 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
openapi: "3.0.2"
info:
title: Armoço
version: "0.0.0"
servers:
- url: http://localhost:8080
paths:
/test:
get:
description: Return a random image object
responses:
"200":
description: OK

/v1/images:
get:
tags:
- images
responses:
"200":
description: OK
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/ImageResponse"
"500":
description: Internal Server Error
post:
tags:
- images
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
file:
type: string
format: binary
responses:
"200":
description: OK
"500":
description: Internal Server Error

components:
schemas:
ImageResponse:
type: object
properties:
id:
type: string
url:
type: string
category:
type: string
14 changes: 14 additions & 0 deletions cmd/armoco/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
package main

import (
"net/http"
"os"
"time"

"github.com/birdie-ai/armoco/api"
"github.com/birdie-ai/golibs/slog"
)

Expand All @@ -17,6 +20,17 @@ func main() {
err = slog.Configure(logcfg)
abortonerr(err)

srv := &http.Server{
Addr: ":8080",
Handler: api.Routes(),
IdleTimeout: time.Minute,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
}
slog.Info("starting service", "addr", srv.Addr)
err = srv.ListenAndServe()
abortonerr(err)

slog.Info("TODO: implement armoco")
}

Expand Down
18 changes: 18 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ go 1.21
require github.com/birdie-ai/golibs/slog v0.0.5

require (
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/birdie-ai/gootstrap v0.0.0-20230810110120-308640d5fc29 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.20.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/loads v0.21.2 // indirect
github.com/go-openapi/runtime v0.26.0 // indirect
github.com/go-openapi/spec v0.20.8 // indirect
github.com/go-openapi/strfmt v0.21.7 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-openapi/validate v0.22.1 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
go.mongodb.org/mongo-driver v1.11.3 // indirect
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 31a073a

Please sign in to comment.