简体   繁体   English

如果数据类型从字符串更改为布尔数据存储,则会引发错误

[英]If the data type changes from string to bool data store is throwing an error

I am storing my struct values in google data store. 我将我的结构值存储在Google数据存储区中。 Here is my struct: 这是我的结构:

type Appointment struct {
    ID                    string 
    Appointment Date      string 
    Start Time            string 
    End Time              string 
    Select Specialization string 
    Smoking Status        string
} 

I have stored some data using datastore, but later changed the data type from string to bool for the field "Smoking Status" then the data store is throwing an error: 我已经使用数据存储存储了一些数据,但后来将“吸烟状态”字段的数据类型从字符串更改为bool,然后数据存储抛出错误:

{"error":{"message":"data store: cannot load field \\"Smoking Status\\" into a \\"simplysthealth.Encounter\\": type mismatch: string versus bool"}} {“错误”:{“消息”:“数据存储:无法将字段“吸烟状态”加载到“ simplysthealth.Encounter”中:类型不匹配:字符串与布尔值”}}

Is there any feasible solution for this? 有什么可行的解决方案吗?

package main

// I have corrected all of your method names
type Appointment struct {
        ID                   string
        AppointmentDate      string
        StartTime            string
        EndTime              string
        SelectSpecialization string
        SmokingStatus        string
}

type AllOldData struct {
        Data []Appointment
}
type FixedAppointment struct {
        ID                   string
        AppointmentDate      string
        StartTime            string
        EndTime              string
        SelectSpecialization string
        SmokingStatus        bool
}

type FixedData struct {
        Data []FixedAppointment
}

func TypeFixing() FixedData {

        var OldData AllOldData
        var NewData FixedData

        OldData = GetYourAllOldData()

        for i, v := range OldData.Data {
                if v.SmokingStatus == "true" {
                        // other value exchanging
                        NewData.Data[i].SmokingStatus = true
                } else {
                        // other value exchanging
                        NewData.Data[i].SmokingStatus = false
                }
        }

        return NewData // Save the data in a new table or whatever you call it

}

func GetYourAllOldData() AllOldData {
        // A function that returns all old data
        return AllOldData{} // You must return return your all data
}

This is what you need to do it manually! 这是您需要手动执行的操作!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 数据类型突然改变 - Data type suddenly changes 如何根据条件将任何数据类型编组为字符串并从字符串解组为特定数据类型 - How to Marshall any data type to string and Unmarshal from string to specific data type on condition 如何将Go通道值存储到其他一些数据类型(字符串,字节[])中,并将其重新分配给其他Go通道 - How to store go channel value into some other data type(string,byte[]) and reassign it other go channel 是否可以从空间中获取多面体类型数据作为字符串? - Is it possible to get multipolygon type data as string from spatialite? 将golang map [string]接口存储到数据存储中的最佳方法 - Best way to store golang map[string]interface into data store 在 Golang 中创建 bool 类型的切片时出错? - Error while creating slice of bool type in Golang? 使用 golang 将字符串数据转换为 valida 结构以存储为 json 数据 - Convert string data in to a valida struct to store as json data using golang 不能在 function 的参数中使用数据(类型 [] 字符串)作为类型字符串 - Cannot use data (type []string) as type string in argument to function 不能在函数参数中使用true(类型bool)作为类型字符串 - cannot use true (type bool) as type string in function argument 无法将数据(类型接口 {})转换为类型字符串:需要类型断言 - cannot convert data (type interface {}) to type string: need type assertion
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM