Fix nil pointer when CLI unable to get server version (#1223)

This commit is contained in:
Ta-Ching Chen
2019-07-07 09:55:00 +08:00
committed by GitHub
parent 9d13081803
commit 9e7dd5aa27
2 changed files with 17 additions and 6 deletions
+9 -1
View File
@@ -18,12 +18,16 @@ package client
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"strings"
"time"
"golang.org/x/net/context/ctxhttp"
ferror "github.com/fission/fission/pkg/error"
"github.com/fission/fission/pkg/info"
@@ -94,7 +98,11 @@ func (c *Client) handleCreateResponse(resp *http.Response) ([]byte, error) {
func (c *Client) ServerInfo() (*info.ServerInfo, error) {
url := fmt.Sprintf(c.Url)
resp, err := http.Get(url)
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
resp, err := ctxhttp.Get(ctx, &http.Client{}, url)
if err != nil {
return nil, err
}
+8 -5
View File
@@ -18,27 +18,30 @@ type Versions struct {
}
func GetVersion(client *client.Client) []byte {
serverInfo, err := client.ServerInfo()
if err != nil {
log.Warn(fmt.Sprintf("Error getting Fission API version: %v", err))
}
// Fetch client versions
versions := Versions{
Client: map[string]info.BuildMeta{
"fission/core": info.BuildInfo(),
},
}
for _, pmd := range plugin.FindAll() {
versions.Client[pmd.Name] = info.BuildMeta{
Version: pmd.Version,
}
}
serverInfo, err := client.ServerInfo()
if err != nil {
log.Warn(fmt.Sprintf("Error getting Fission API version: %v", err))
serverInfo = &info.ServerInfo{}
}
// Fetch server versions
versions.Server = map[string]info.BuildMeta{
"fission/core": serverInfo.Build,
}
// FUTURE: fetch versions of plugins server-side
bs, err := yaml.Marshal(versions)
if err != nil {