6
6
"fmt"
7
7
"html/template"
8
8
"io"
9
- "io/ioutil"
10
9
"log"
11
10
"net/http"
12
11
"path/filepath"
@@ -26,8 +25,6 @@ import (
26
25
highlighting "github.com/yuin/goldmark-highlighting"
27
26
28
27
"embed"
29
-
30
- "github.com/song940/gitgo/githttp"
31
28
)
32
29
33
30
//go:embed templates
@@ -172,6 +169,9 @@ func RenderSyntaxHighlighting(file *object.File) (string, error) {
172
169
)
173
170
174
171
iterator , err := lexer .Tokenise (nil , contents )
172
+ if err != nil {
173
+ return "" , err
174
+ }
175
175
176
176
buf := bytes .NewBuffer (nil )
177
177
err = formatter .Format (buf , style , iterator )
@@ -184,17 +184,17 @@ func RenderSyntaxHighlighting(file *object.File) (string, error) {
184
184
}
185
185
186
186
func Http404 (ctx * gin.Context ) {
187
- smithyConfig := ctx .MustGet ("config" ).(SmithyConfig )
187
+ smithyConfig := ctx .MustGet ("config" ).(Smithy )
188
188
ctx .HTML (http .StatusNotFound , "404.html" , makeTemplateContext (smithyConfig , gin.H {}))
189
189
}
190
190
191
191
func Http500 (ctx * gin.Context ) {
192
- smithyConfig := ctx .MustGet ("config" ).(SmithyConfig )
192
+ smithyConfig := ctx .MustGet ("config" ).(Smithy )
193
193
ctx .HTML (http .StatusInternalServerError , "500.html" ,
194
194
makeTemplateContext (smithyConfig , gin.H {}))
195
195
}
196
196
197
- func makeTemplateContext (config SmithyConfig , extra gin.H ) gin.H {
197
+ func makeTemplateContext (config Smithy , extra gin.H ) gin.H {
198
198
results := gin.H {
199
199
"Site" : gin.H {
200
200
"Title" : config .Title ,
@@ -209,7 +209,7 @@ func makeTemplateContext(config SmithyConfig, extra gin.H) gin.H {
209
209
}
210
210
211
211
func IndexView (ctx * gin.Context , urlParts []string ) {
212
- smithyConfig := ctx .MustGet ("config" ).(SmithyConfig )
212
+ smithyConfig := ctx .MustGet ("config" ).(Smithy )
213
213
repos := smithyConfig .GetRepositories ()
214
214
215
215
ctx .HTML (http .StatusOK , "index.html" , makeTemplateContext (smithyConfig , gin.H {
@@ -230,7 +230,7 @@ func findMainBranch(ctx *gin.Context, repo *git.Repository) (string, *plumbing.H
230
230
231
231
func RepoIndexView (ctx * gin.Context , urlParts []string ) {
232
232
repoName := urlParts [0 ]
233
- smithyConfig := ctx .MustGet ("config" ).(SmithyConfig )
233
+ smithyConfig := ctx .MustGet ("config" ).(Smithy )
234
234
repo , exists := smithyConfig .FindRepo (repoName )
235
235
236
236
if ! exists {
@@ -293,14 +293,14 @@ func RepoIndexView(ctx *gin.Context, urlParts []string) {
293
293
}
294
294
295
295
func RepoGitView (ctx * gin.Context , urlParts []string ) {
296
- smithyConfig := ctx .MustGet ("config" ).(SmithyConfig )
297
- git := githttp .New (smithyConfig .Git .Root )
298
- git .ServeHTTP (ctx .Writer , ctx .Request )
296
+ // smithyConfig := ctx.MustGet("config").(Smithy )
297
+ // git := githttp.New(smithyConfig.Git.Root)
298
+ // git.ServeHTTP(ctx.Writer, ctx.Request)
299
299
}
300
300
301
301
func RefsView (ctx * gin.Context , urlParts []string ) {
302
302
repoName := urlParts [0 ]
303
- smithyConfig := ctx .MustGet ("config" ).(SmithyConfig )
303
+ smithyConfig := ctx .MustGet ("config" ).(Smithy )
304
304
repo , exists := smithyConfig .FindRepo (repoName )
305
305
306
306
if ! exists {
@@ -328,7 +328,7 @@ func RefsView(ctx *gin.Context, urlParts []string) {
328
328
329
329
func TreeView (ctx * gin.Context , urlParts []string ) {
330
330
repoName := urlParts [0 ]
331
- smithyConfig := ctx .MustGet ("config" ).(SmithyConfig )
331
+ smithyConfig := ctx .MustGet ("config" ).(Smithy )
332
332
repo , exists := smithyConfig .FindRepo (repoName )
333
333
334
334
if ! exists {
@@ -438,7 +438,7 @@ func TreeView(ctx *gin.Context, urlParts []string) {
438
438
439
439
func LogView (ctx * gin.Context , urlParts []string ) {
440
440
repoName := urlParts [0 ]
441
- smithyConfig := ctx .MustGet ("config" ).(SmithyConfig )
441
+ smithyConfig := ctx .MustGet ("config" ).(Smithy )
442
442
repo , exists := smithyConfig .FindRepo (repoName )
443
443
if ! exists {
444
444
Http404 (ctx )
@@ -485,7 +485,7 @@ func LogView(ctx *gin.Context, urlParts []string) {
485
485
486
486
func LogViewDefault (ctx * gin.Context , urlParts []string ) {
487
487
repoName := urlParts [0 ]
488
- smithyConfig := ctx .MustGet ("config" ).(SmithyConfig )
488
+ smithyConfig := ctx .MustGet ("config" ).(Smithy )
489
489
repo , exists := smithyConfig .FindRepo (repoName )
490
490
if ! exists {
491
491
Http404 (ctx )
@@ -540,7 +540,7 @@ func FormatChanges(changes object.Changes) (string, error) {
540
540
func PatchView (ctx * gin.Context , urlParts []string ) {
541
541
const commitFormatDate = "Mon, 2 Jan 2006 15:04:05 -0700"
542
542
repoName := urlParts [0 ]
543
- smithyConfig := ctx .MustGet ("config" ).(SmithyConfig )
543
+ smithyConfig := ctx .MustGet ("config" ).(Smithy )
544
544
repo , exists := smithyConfig .FindRepo (repoName )
545
545
if ! exists {
546
546
Http404 (ctx )
@@ -600,7 +600,7 @@ func PatchView(ctx *gin.Context, urlParts []string) {
600
600
601
601
func CommitView (ctx * gin.Context , urlParts []string ) {
602
602
repoName := urlParts [0 ]
603
- smithyConfig := ctx .MustGet ("config" ).(SmithyConfig )
603
+ smithyConfig := ctx .MustGet ("config" ).(Smithy )
604
604
repo , exists := smithyConfig .FindRepo (repoName )
605
605
if ! exists {
606
606
Http404 (ctx )
@@ -639,7 +639,7 @@ func CommitView(ctx *gin.Context, urlParts []string) {
639
639
}
640
640
641
641
// Make the config available to every request
642
- func AddConfigMiddleware (cfg SmithyConfig ) gin.HandlerFunc {
642
+ func AddConfigMiddleware (cfg Smithy ) gin.HandlerFunc {
643
643
return func (c * gin.Context ) {
644
644
c .Set ("config" , cfg )
645
645
}
@@ -705,7 +705,6 @@ func Dispatch(ctx *gin.Context, routes []Route, fileSystemHandler http.Handler)
705
705
if ! route .Pattern .MatchString (urlPath ) {
706
706
continue
707
707
}
708
-
709
708
urlParts := []string {}
710
709
for i , match := range route .Pattern .FindStringSubmatch (urlPath ) {
711
710
if i != 0 {
@@ -715,15 +714,11 @@ func Dispatch(ctx *gin.Context, routes []Route, fileSystemHandler http.Handler)
715
714
716
715
route .View (ctx , urlParts )
717
716
return
718
-
719
717
}
720
-
721
718
Http404 (ctx )
722
-
723
719
}
724
720
725
- func loadTemplates (smithyConfig SmithyConfig ) (* template.Template , error ) {
726
-
721
+ func loadTemplates () (* template.Template , error ) {
727
722
funcs := template.FuncMap {
728
723
// "css": func() string {
729
724
// return cssPath
@@ -743,7 +738,7 @@ func loadTemplates(smithyConfig SmithyConfig) (*template.Template, error) {
743
738
if err != nil {
744
739
return t , err
745
740
}
746
- contents , err := ioutil .ReadAll (f )
741
+ contents , err := io .ReadAll (f )
747
742
if err != nil {
748
743
return t , err
749
744
}
0 commit comments