File tree Expand file tree Collapse file tree 2 files changed +26
-19
lines changed Expand file tree Collapse file tree 2 files changed +26
-19
lines changed Original file line number Diff line number Diff line change @@ -2,12 +2,10 @@ package utils
2
2
3
3
import (
4
4
"github.com/gin-gonic/gin"
5
- "io"
6
- "os"
7
-
8
5
"github.com/lessapidev/lessapi-duckduckgo/internal/types"
9
6
)
10
7
8
+ // BuildApiSuccess returns a new ApiResponse with code "success" and empty data.
11
9
func BuildApiSuccess () * types.ApiResponse [any ] {
12
10
return & types.ApiResponse [any ]{
13
11
Code : "success" ,
@@ -16,6 +14,7 @@ func BuildApiSuccess() *types.ApiResponse[any] {
16
14
}
17
15
}
18
16
17
+ // BuildApiSuccessData returns a new ApiResponse with code "success" and the given data.
19
18
func BuildApiSuccessData [T any ](data T ) * types.ApiResponse [T ] {
20
19
return & types.ApiResponse [T ]{
21
20
Code : "success" ,
@@ -25,25 +24,10 @@ func BuildApiSuccessData[T any](data T) *types.ApiResponse[T] {
25
24
26
25
}
27
26
27
+ // BuildApiError returns a new ApiResponse with the given error code and message.
28
28
func BuildApiError (errCode string , errorMessage string ) * types.ApiResponse [any ] {
29
29
return & types.ApiResponse [any ]{
30
30
Code : errCode ,
31
31
Message : & errorMessage ,
32
32
}
33
33
}
34
-
35
- func ReadLocalFile (filename string ) (string , error ) {
36
- file , err := os .Open (filename )
37
- if err != nil {
38
- return "" , err
39
- }
40
- defer func () {
41
- _ = file .Close ()
42
- }()
43
-
44
- data , err := io .ReadAll (file )
45
- if err != nil {
46
- return "" , err
47
- }
48
- return string (data ), nil
49
- }
Original file line number Diff line number Diff line change
1
+ package utils
2
+
3
+ import (
4
+ "io"
5
+ "os"
6
+ )
7
+
8
+ // ReadLocalFile reads the content of the file with the given filename.
9
+ func ReadLocalFile (filename string ) (string , error ) {
10
+ file , err := os .Open (filename )
11
+ if err != nil {
12
+ return "" , err
13
+ }
14
+ defer func () {
15
+ _ = file .Close ()
16
+ }()
17
+
18
+ data , err := io .ReadAll (file )
19
+ if err != nil {
20
+ return "" , err
21
+ }
22
+ return string (data ), nil
23
+ }
You can’t perform that action at this time.
0 commit comments