Skip to content

Commit

Permalink
fix: mapGender
Browse files Browse the repository at this point in the history
  • Loading branch information
lxw665 committed Jun 21, 2024
1 parent 6cad29a commit 19e633e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions internal/api/provider/wechat.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"github.com/supabase/gotrue/internal/conf"
"golang.org/x/oauth2"
"io"
"log"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -92,12 +92,13 @@ func (idp weChatProvider) GetOAuthToken(code string) (*oauth2.Token, error) {
if err != nil {
return nil, err
}
defer func(Body io.ReadCloser) {
err := Body.Close()
defer func() {
err := tokenResponse.Body.Close()
if err != nil {
log.Fatalf("Failed to close response body: %v", err)
return
}
}(tokenResponse.Body)
}()
buf := new(bytes.Buffer)
_, err = buf.ReadFrom(tokenResponse.Body)
if err != nil {
Expand Down Expand Up @@ -157,12 +158,13 @@ func (idp weChatProvider) GetUserData(ctx context.Context, token *oauth2.Token)
return nil, fmt.Errorf("get user info error: %v", err)

}
defer func(Body io.ReadCloser) {
err := Body.Close()
defer func() {
err := resp.Body.Close()
if err != nil {
log.Fatalf("Failed to close response body: %v", err)
return
}
}(resp.Body)
}()
buf := new(bytes.Buffer)
_, err = buf.ReadFrom(resp.Body)
if err != nil {
Expand Down Expand Up @@ -194,9 +196,9 @@ func (idp weChatProvider) GetUserData(ctx context.Context, token *oauth2.Token)

func mapGender(sex int) string {
switch sex {
case 1:
case 0:
return "male"
case 2:
case 1:
return "female"
default:
return "unknown"
Expand Down

0 comments on commit 19e633e

Please sign in to comment.