-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (50 loc) · 830 Bytes
/
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 (
"fmt"
"github.com/gin-gonic/gin"
"net/http"
"strconv"
)
func main() {
fmt.Println(IsPalindrome("aba"))
}
func GetUser(c *gin.Context) {
id, _ := strconv.Atoi(c.Param("id"))
user, err := GetUserInfo(id)
if err != nil {
c.JSON(500, &Resp{
Code: "500",
Msg: "",
Data: nil,
})
}
c.JSON(http.StatusOK, &Resp{
Code: "200",
Msg: "",
Data: user,
})
}
type Resp struct {
Code string `json:"code"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
}
type User struct {
Id int `json:"id"`
Name string `json:"name"`
}
func GetUserInfo(id int) (*User, error) {
return &User{
Id: id,
Name: "xiaoming",
}, nil
}
func IsPalindrome(s string) bool {
n := len(s)
for i := 0; i < n/2; i++ {
if s[i] != s[n-1-i] {
return false
}
}
return true
}