@@ -7,14 +7,13 @@ package web
7
7
import (
8
8
"net/http"
9
9
"net/url"
10
+ "os"
10
11
"path"
11
12
"strings"
12
13
13
14
repo_model "code.gitea.io/gitea/models/repo"
14
15
"code.gitea.io/gitea/modules/context"
15
- "code.gitea.io/gitea/modules/log"
16
16
"code.gitea.io/gitea/modules/setting"
17
- "code.gitea.io/gitea/modules/templates/vars"
18
17
"code.gitea.io/gitea/modules/util"
19
18
)
20
19
@@ -67,35 +66,37 @@ func goGet(ctx *context.Context) {
67
66
}
68
67
ctx .RespHeader ().Set ("Content-Type" , "text/html" )
69
68
ctx .Status (http .StatusOK )
70
- res , err := vars .Expand (`<!doctype html>
69
+ res := os .Expand (`<!doctype html>
71
70
<html>
72
71
<head>
73
- <meta name="go-import" content="{GoGetImport} git {CloneLink}">
74
- <meta name="go-source" content="{GoGetImport} _ {GoDocDirectory} {GoDocFile}">
72
+ <meta name="go-import" content="$ {GoGetImport} git $ {CloneLink}">
73
+ <meta name="go-source" content="$ {GoGetImport} _ $ {GoDocDirectory} $ {GoDocFile}">
75
74
</head>
76
75
<body>
77
- go get {Insecure}{GoGetImport}
76
+ go get $ {Insecure}$ {GoGetImport}
78
77
</body>
79
78
</html>
80
- ` , map [string ]string {
81
- "GoGetImport" : context .ComposeGoGetImport (ownerName , trimmedRepoName ),
82
- "CloneLink" : repo_model .ComposeHTTPSCloneURL (ownerName , repoName ),
83
- "GoDocDirectory" : prefix + "{/dir}" ,
84
- "GoDocFile" : prefix + "{/dir}/{file}#L{line}" ,
85
- "Insecure" : insecure ,
79
+ ` , func (key string ) string {
80
+ switch key {
81
+ case "GoGetImport" :
82
+ return context .ComposeGoGetImport (ownerName , trimmedRepoName )
83
+ case "CloneLink" :
84
+ return repo_model .ComposeHTTPSCloneURL (ownerName , repoName )
85
+ case "GoDocDirectory" :
86
+ return prefix + "{/dir}"
87
+ case "GoDocFile" :
88
+ return prefix + "{/dir}/{file}#L{line}"
89
+ case "Insecure" :
90
+ return insecure
91
+ default :
92
+ return `<!doctype html>
93
+ <html>
94
+ <body>
95
+ invalid import path
96
+ </body>
97
+ </html>
98
+ `
99
+ }
86
100
})
87
- if err != nil {
88
- log .Error (err .Error ())
89
- _ , _ = ctx .Write ([]byte (`<!doctype html>
90
- <html>
91
- <body>
92
- invalid import path
93
- </body>
94
- </html>
95
- ` ))
96
- ctx .Status (400 )
97
- return
98
- }
99
-
100
101
_ , _ = ctx .Write ([]byte (res ))
101
102
}
0 commit comments