-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathserver.go
49 lines (42 loc) · 2.06 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
"net/http"
"github.com/go-swagno/swagno"
"github.com/go-swagno/swagno/components/endpoint"
"github.com/go-swagno/swagno/components/http/response"
"github.com/go-swagno/swagno/components/mime"
"github.com/go-swagno/swagno/components/parameter"
"github.com/go-swagno/swagno/example/models"
"github.com/go-swagno/swagno-http/swagger"
)
func main() {
sw := swagno.New(swagno.Config{Title: "Testing API", Version: "v1.0.0"})
desc := "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed id malesuada lorem, et fermentum sapien. Vivamus non pharetra risus, in efficitur leo. Suspendisse sed metus sit amet mi laoreet imperdiet. Donec aliquam eros eu blandit feugiat. Quisque scelerisque justo ac vehicula bibendum. Fusce suscipit arcu nisl, eu maximus odio consequat quis. Curabitur fermentum eleifend tellus, lobortis hendrerit velit varius vitae."
endpoints := []*endpoint.EndPoint{
endpoint.New(
endpoint.GET,
"/product",
endpoint.WithTags("product"),
endpoint.WithSuccessfulReturns([]response.Response{response.New(models.Product{}, "200", "OK")}),
endpoint.WithErrors([]response.Response{response.New(models.UnsuccessfulResponse{}, "400", "Bad Request")}),
endpoint.WithDescription(desc),
endpoint.WithProduce([]mime.MIME{mime.JSON, mime.XML}),
endpoint.WithConsume([]mime.MIME{mime.JSON}),
endpoint.WithSummary("this is a test summary"),
),
endpoint.New(
endpoint.GET,
"/product/{id}",
endpoint.WithTags("product"),
endpoint.WithParams(parameter.IntParam("id", parameter.Path, parameter.WithRequired())),
endpoint.WithSuccessfulReturns([]response.Response{response.New(models.SuccessfulResponse{}, "200", "Request Accepted")}),
endpoint.WithErrors([]response.Response{response.New(models.UnsuccessfulResponse{}, "400", "Bad Request")}),
endpoint.WithProduce([]mime.MIME{mime.JSON, mime.XML}),
),
}
sw.AddEndpoints(endpoints)
http.HandleFunc("/swagger/", swagger.SwaggerHandler(sw.MustToJson()))
fmt.Println("Server is running on http://localhost:8080")
http.ListenAndServe(":8080", nil)
}