第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

函數(shù)不適用于 if else 語句

函數(shù)不適用于 if else 語句

Go
寶慕林4294392 2022-08-01 16:53:45
我正在嘗試使用Go作為教程構(gòu)建一個(gè)基本的緩存系統(tǒng)。由于某種原因,當(dāng)我運(yùn)行這個(gè)時(shí),if else語句會(huì)導(dǎo)致錯(cuò)誤。package datasourceimport (    "fmt"    "github.com/patrickmn/go-cache"    "time")type DataSource interface {    Value(key string) (interface{}, error)}// DataSourceStr type, implements the DataSource interfacetype DataSourceStr struct {    data map[string]string}var cache = cache.New(5*time.Minute, 5*time.Minute)func (n *DataSourceStr) Value(key string) (interface{}, error) {        /*     1. Compute a cache key    2. Search cache key    3. If hit return value    4. If miss, do datasource    5. Cache and return slow thing.    */        cached, found := cache.Value(key)    if found {        return cached, nil    }    else if _, ok := n.data[key]; ok     {        //measure how often a key gets called.        cache.Set(key, n.data[key], cache.DefaultExpiration)        return n.data[key], nil    } else {        return nil, fmt.Errorf("key not found %v", ok)    }}func getFromDS(datasource DataSource, key string) (string, error) {        v, err := datasource.Value(key)        //create a map that decays based on time.    if err != nil {        return "", nil    }    return fmt.Sprint(v), nil}我做錯(cuò)了什么?我正在嘗試輸入一個(gè)密鑰,然后從緩存或數(shù)據(jù)庫中返回值。不知道我在語法上做錯(cuò)了什么!
查看完整描述

1 回答

?
心有法竹

TA貢獻(xiàn)1866條經(jīng)驗(yàn) 獲得超5個(gè)贊

go 條件語句遵循以下語法


   if something{

      ......


   } else if something{

      ......


   } else{

      ......

   }


查看完整回答
反對(duì) 回復(fù) 2022-08-01
  • 1 回答
  • 0 關(guān)注
  • 111 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)