doupi4649 2016-05-12 00:20
浏览 10
已采纳

Gocql自定义封送员

I have a table with a tuple column that is made up of an int64 paired with a uuid:

CREATE TABLE ks.mytable {
    fileid    frozen <tuple <bigint, uuid>>,
    hits      counter,
    ...

and I can currently set the field using a cql statement like:

UPDATE ks.mytable hits = hits + 1 WHERE fileid=(? ?);

and I pass in 2 variables as arguments, an int64 and a gocql.UUID.

Instead of moving 2 variables around everywhere, I want to put these in a struct, something like

type MyID struct {
    id  int64
    uid  gocql.UUID
}

then use a Marshaller to pass these into the UPDATE statement.

Is this possible? I am not sure if I can pass in a single variable for the tuple field. If so, how can I do this? I can't figure out how - I was trying to mimic https://github.com/gocql/gocql/blob/master/marshal_test.go#L935 but I'm getting errors where I can't set the fields in the struct (cannot refer to unexported field or method proto)

  • 写回答

1条回答 默认 最新

  • douhuibo5635 2016-05-13 12:42
    关注

    As you mentioned, you are getting the following error:

    cannot refer to unexported field or method proto

    This means you need to export your fields inside the struct and that means beginning with a capital letter in Go. So your struct should be:

    type MyID struct {
        Id  int64
        Uid  gocql.UUID
    }
    

    Then, it should work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)