-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.go
57 lines (45 loc) · 1.55 KB
/
main.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
50
51
52
53
54
55
56
57
package main
import (
"flag"
"fmt"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
_ "github.com/kairoaraujo/goca/v2/docs"
"github.com/kairoaraujo/goca/v2/rest-api/controllers"
)
// @title GoCA API
// @description GoCA Certificate Authority Management API.
// @schemes http https
// @securityDefinitions.basic BasicAuth
// @contact.name GoCA API Issues Report
// @contact.url http://github.com/kairoaraujo/goca/issues
// @license.name MIT
// @license.url https://opensource.org/licenses/MIT
func main() {
var port int
flag.IntVar(&port, "p", 80, "Port to listen, default is 80")
flag.Parse()
router := gin.Default()
// Set a lower memory limit for multipart forms (default is 32 MiB)
router.MaxMultipartMemory = 8 << 20 // 8 MiB
router.Use(gin.Logger())
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
api := router.Group("/api")
v1 := api.Group("/v1")
// Routes
v1.GET("/ca", controllers.GetCA)
v1.POST("/ca", controllers.AddCA)
v1.GET("/ca/:cn", controllers.GetCACommonName)
v1.POST("/ca/:cn/sign", controllers.SignCSR)
v1.POST("/ca/:cn/upload", controllers.UploadCertificateICA)
v1.GET("/ca/:cn/certificates", controllers.GetCertificates)
v1.POST("/ca/:cn/certificates", controllers.IssueCertificates)
v1.DELETE("/ca/:cn/certificates/:cert_cn", controllers.RevokeCertificate)
v1.GET("/ca/:cn/certificates/:cert_cn", controllers.GetCertificatesCommonName)
// Run the server
err := router.Run(fmt.Sprintf(":%d", port))
if err != nil {
panic(err)
}
}