Skip to content

Commit

Permalink
remove templating
Browse files Browse the repository at this point in the history
  • Loading branch information
decentralgabe committed Jul 28, 2023
1 parent f2280d0 commit 2bd4d40
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 50 deletions.
3 changes: 1 addition & 2 deletions cmd/ssiservice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ import (
// main godoc
//
// @title SSI Service API
// @description {{.Desc}}
// @description The Self Sovereign Identity Service: Managing DIDs, Verifiable Credentials, and more!
// @contact.name TBD
// @contact.url https://github.com/TBD54566975/ssi-service/issues
// @contact.email [email protected]
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @version {{.SVN}}
func main() {
logrus.Info("Starting up...")

Expand Down
4 changes: 3 additions & 1 deletion doc/howto/did.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
package howto
# How To: Create a DID

With a running SSI Service at
4 changes: 2 additions & 2 deletions doc/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2198,12 +2198,12 @@ info:
email: [email protected]
name: TBD
url: https://github.com/TBD54566975/ssi-service/issues
description: '{{.Desc}}'
description: 'The Self Sovereign Identity Service: Managing DIDs, Verifiable Credentials,
and more!'
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
title: SSI Service API
version: '{{.SVN}}'
paths:
/health:
get:
Expand Down
47 changes: 2 additions & 45 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
package server

import (
"bytes"
"context"
"os"
"text/template"

sdkutil "github.com/TBD54566975/ssi-sdk/util"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
swaggerfiles "github.com/swaggo/files"
ginswagger "github.com/swaggo/gin-swagger"
"go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin"
Expand Down Expand Up @@ -72,23 +68,8 @@ func NewSSIServer(shutdown chan os.Signal, cfg config.SSIServiceConfig) (*SSISer
// service-level routers
engine.GET(HealthPrefix, router.Health)
engine.GET(ReadinessPrefix, router.Readiness(ssi.GetServices()))

tmpFile, err := writeSwaggerFile(cfg)
if err != nil {
logrus.WithError(err).Warnf("unable to write swagger file, skipping handler")
} else {
httpServer.RegisterPreShutdownHook(func(_ context.Context) error {
logrus.Infof("removing temp file %q", tmpFile.Name())
err := os.Remove(tmpFile.Name())
if err != nil {
logrus.WithError(err).Warnf("unable to delete %q during shutdown", tmpFile.Name())
}
return nil
})

engine.StaticFile("swagger.yaml", tmpFile.Name())
engine.GET(SwaggerPrefix, ginswagger.WrapHandler(swaggerfiles.Handler, ginswagger.URL("/swagger.yaml")))
}
engine.StaticFile("swagger.yaml", "./doc/swagger.yaml")
engine.GET("/swagger/*any", ginswagger.WrapHandler(swaggerfiles.Handler, ginswagger.URL("/swagger.yaml")))

// register all v1 routers
v1 := engine.Group(V1Prefix)
Expand Down Expand Up @@ -130,30 +111,6 @@ func NewSSIServer(shutdown chan os.Signal, cfg config.SSIServiceConfig) (*SSISer
}, nil
}

func writeSwaggerFile(cfg config.SSIServiceConfig) (*os.File, error) {
t, err := template.ParseFiles("./doc/swagger.yaml")
if err != nil {
return nil, err
}

var b bytes.Buffer
if err = t.Execute(&b, cfg); err != nil {
return nil, err
}
tmpFile, err := os.CreateTemp("", "swagger.yaml")
if err != nil {
return nil, err
}

if _, err = tmpFile.Write(b.Bytes()); err != nil {
return nil, err
}
if err := tmpFile.Close(); err != nil {
return nil, err
}
return tmpFile, nil
}

// setUpEngine creates the gin engine and sets up the middleware based on config
func setUpEngine(cfg config.ServerConfig, shutdown chan os.Signal) *gin.Engine {
gin.ForceConsoleColor()
Expand Down

0 comments on commit 2bd4d40

Please sign in to comment.