Best K6 code snippet using json.Start
utopiaplugin.go
Source:utopiaplugin.go
...4const (5 Version = "1"6 ID = "UtopiaCoinOrg"7 CmdAuthorizeVote = "authorizevote"8 CmdStartVote = "startvote"9 CmdVoteDetails = "votedetails"10 CmdVoteSummary = "votesummary"11 CmdLoadVoteResults = "loadvoteresults"12 CmdBallot = "ballot"13 CmdBestBlock = "bestblock"14 CmdNewComment = "newcomment"15 CmdLikeComment = "likecomment"16 CmdCensorComment = "censorcomment"17 CmdGetComment = "getcomment"18 CmdGetComments = "getcomments"19 CmdGetNumComments = "getnumcomments"20 CmdProposalVotes = "proposalvotes"21 CmdCommentLikes = "commentlikes"22 CmdProposalCommentsLikes = "proposalcommentslikes"23 CmdInventory = "inventory"24 CmdTokenInventory = "tokeninventory"25 MDStreamAuthorizeVote = 13 // Vote authorization by proposal author26 MDStreamVoteBits = 14 // Vote bits and mask27 MDStreamVoteSnapshot = 15 // Vote tickets and start/end parameters28 VoteDurationMin = 2016 // Minimum vote duration (in blocks)29 VoteDurationMax = 4032 // Maximum vote duration (in blocks)30 // Authorize vote actions31 AuthVoteActionAuthorize = "authorize" // Authorize a proposal vote32 AuthVoteActionRevoke = "revoke" // Revoke a proposal vote authorization33)34// CastVote is a signed vote.35type CastVote struct {36 Token string `json:"token"` // Proposal ID37 Ticket string `json:"ticket"` // Ticket ID38 VoteBit string `json:"votebit"` // Vote bit that was selected, this is encode in hex39 Signature string `json:"signature"` // Signature of Token+Ticket+VoteBit40}41// Ballot is a batch of votes that are sent to the server.42type Ballot struct {43 Votes []CastVote `json:"votes"`44}45// EncodeCastVotes encodes CastVotes into a JSON byte slice.46func EncodeBallot(b Ballot) ([]byte, error) {47 return json.Marshal(b)48}49// DecodeCastVotes decodes a JSON byte slice into a CastVotes.50func DecodeBallot(payload []byte) (*Ballot, error) {51 var b Ballot52 err := json.Unmarshal(payload, &b)53 if err != nil {54 return nil, err55 }56 return &b, nil57}58// CastVoteReply contains the signature or error to a cast vote command.59type CastVoteReply struct {60 ClientSignature string `json:"clientsignature"` // Signature that was sent in61 Signature string `json:"signature"` // Signature of the ClientSignature62 Error string `json:"error"` // Error if something wen't wrong during casting a vote63}64// EncodeCastVoteReply encodes CastVoteReply into a JSON byte slice.65func EncodeCastVoteReply(cvr CastVoteReply) ([]byte, error) {66 return json.Marshal(cvr)67}68// DecodeBallotReply decodes a JSON byte slice into a CastVotes.69func DecodeCastVoteReply(payload []byte) (*CastVoteReply, error) {70 var cvr CastVoteReply71 err := json.Unmarshal(payload, &cvr)72 if err != nil {73 return nil, err74 }75 return &cvr, nil76}77// BallotReply is a reply to a batched list of votes.78type BallotReply struct {79 Receipts []CastVoteReply `json:"receipts"`80}81// EncodeCastVoteReplies encodes CastVotes into a JSON byte slice.82func EncodeBallotReply(br BallotReply) ([]byte, error) {83 return json.Marshal(br)84}85// DecodeBallotReply decodes a JSON byte slice into a CastVotes.86func DecodeBallotReply(payload []byte) (*BallotReply, error) {87 var br BallotReply88 err := json.Unmarshal(payload, &br)89 if err != nil {90 return nil, err91 }92 return &br, nil93}94// VoteOption describes a single vote option.95type VoteOption struct {96 Id string `json:"id"` // Single unique word identifying vote (e.g. yes)97 Description string `json:"description"` // Longer description of the vote.98 Bits uint64 `json:"bits"` // Bits used for this option99}100// Vote represents the vote options for vote that is identified by its token.101type Vote struct {102 Token string `json:"token"` // Token that identifies vote103 Mask uint64 `json:"mask"` // Valid votebits104 Duration uint32 `json:"duration"` // Duration in blocks105 QuorumPercentage uint32 `json:"quorumpercentage"` // Percent of eligible votes required for quorum106 PassPercentage uint32 `json:"passpercentage"` // Percent of total votes required to pass107 Options []VoteOption `json:"options"` // Vote option108}109// EncodeVote encodes Vote into a JSON byte slice.110func EncodeVote(v Vote) ([]byte, error) {111 return json.Marshal(v)112}113// DecodeVote decodes a JSON byte slice into a Vote.114func DecodeVote(payload []byte) (*Vote, error) {115 var v Vote116 err := json.Unmarshal(payload, &v)117 if err != nil {118 return nil, err119 }120 return &v, nil121}122// AuthorizeVote is an MDStream that is used to indicate that a proposal has123// been finalized and is ready to be voted on. The signature and public124// key are from the proposal author. The author can revoke a previously sent125// vote authorization by setting the Action field to revoke.126const VersionAuthorizeVote = 1127type AuthorizeVote struct {128 // Generated by ucplugin129 Version uint `json:"version"` // Version of this structure130 Receipt string `json:"receipt"` // Server signature of client signature131 Timestamp int64 `json:"timestamp"` // Received UNIX timestamp132 // Generated by client133 Action string `json:"action"` // Authorize or revoke134 Token string `json:"token"` // Proposal censorship token135 Signature string `json:"signature"` // Signature of token+version+action136 PublicKey string `json:"publickey"` // Pubkey used for signature137}138// EncodeAuthorizeVote encodes AuthorizeVote into a JSON byte slice.139func EncodeAuthorizeVote(av AuthorizeVote) ([]byte, error) {140 return json.Marshal(av)141}142// DecodeAuthorizeVote decodes a JSON byte slice into an AuthorizeVote.143func DecodeAuthorizeVote(payload []byte) (*AuthorizeVote, error) {144 var av AuthorizeVote145 err := json.Unmarshal(payload, &av)146 if err != nil {147 return nil, err148 }149 return &av, nil150}151// AuthorizeVoteReply returns the authorize vote action that was executed and152// the receipt for the action. The receipt is the server side signature of153// AuthorizeVote.Signature.154type AuthorizeVoteReply struct {155 Action string `json:"action"` // Authorize or revoke156 RecordVersion string `json:"recordversion"` // Version of record files157 Receipt string `json:"receipt"` // Server signature of client signature158 Timestamp int64 `json:"timestamp"` // Received UNIX timestamp159}160// EncodeAuthorizeVote encodes AuthorizeVoteReply into a JSON byte slice.161func EncodeAuthorizeVoteReply(avr AuthorizeVoteReply) ([]byte, error) {162 return json.Marshal(avr)163}164// DecodeAuthorizeVoteReply decodes a JSON byte slice into a AuthorizeVoteReply.165func DecodeAuthorizeVoteReply(payload []byte) (*AuthorizeVoteReply, error) {166 var avr AuthorizeVoteReply167 err := json.Unmarshal(payload, &avr)168 if err != nil {169 return nil, err170 }171 return &avr, nil172}173// StartVote instructs the plugin to commence voting on a proposal with the174// provided vote bits.175const VersionStartVote = 1176type StartVote struct {177 // UtopiaCoinOrg plugin only data178 Version uint `json:"version"` // Version of this structure179 PublicKey string `json:"publickey"` // Key used for signature.180 Vote Vote `json:"vote"` // Vote + options181 Signature string `json:"signature"` // Signature of Votehash182}183// EncodeStartVoteencodes StartVoteinto a JSON byte slice.184func EncodeStartVote(v StartVote) ([]byte, error) {185 return json.Marshal(v)186}187// DecodeVotedecodes a JSON byte slice into a StartVote.188func DecodeStartVote(payload []byte) (*StartVote, error) {189 var sv StartVote190 err := json.Unmarshal(payload, &sv)191 if err != nil {192 return nil, err193 }194 return &sv, nil195}196// StartVoteReply is the reply to StartVote.197const VersionStartVoteReply = 1198type StartVoteReply struct {199 // UtopiaCoinOrg plugin only data200 Version uint `json:"version"` // Version of this structure201 // Shared data202 StartBlockHeight string `json:"startblockheight"` // Block height203 StartBlockHash string `json:"startblockhash"` // Block hash204 EndHeight string `json:"endheight"` // Height of vote end205 EligibleTickets []string `json:"eligibletickets"` // Valid voting tickets206}207// EncodeStartVoteReply encodes StartVoteReply into a JSON byte slice.208func EncodeStartVoteReply(v StartVoteReply) ([]byte, error) {209 return json.Marshal(v)210}211// DecodeVoteReply decodes a JSON byte slice into a StartVoteReply.212func DecodeStartVoteReply(payload []byte) (*StartVoteReply, error) {213 var v StartVoteReply214 err := json.Unmarshal(payload, &v)215 if err != nil {216 return nil, err217 }218 return &v, nil219}220// VoteDetails is used to retrieve the voting period details for a record.221type VoteDetails struct {222 Token string `json:"token"` // Censorship token223}224// EncodeVoteDetails encodes VoteDetails into a JSON byte slice.225func EncodeVoteDetails(vd VoteDetails) ([]byte, error) {226 return json.Marshal(vd)227}228// DecodeVoteDetails decodes a JSON byte slice into a VoteDetails.229func DecodeVoteDetails(payload []byte) (*VoteDetails, error) {230 var vd VoteDetails231 err := json.Unmarshal(payload, &vd)232 if err != nil {233 return nil, err234 }235 return &vd, nil236}237// VoteDetailsReply is the reply to VoteDetails.238type VoteDetailsReply struct {239 AuthorizeVote AuthorizeVote `json:"authorizevote"` // Vote authorization240 StartVote StartVote `json:"startvote"` // Vote ballot241 StartVoteReply StartVoteReply `json:"startvotereply"` // Start vote snapshot242}243// EncodeVoteDetailsReply encodes VoteDetailsReply into a JSON byte slice.244func EncodeVoteDetailsReply(vdr VoteDetailsReply) ([]byte, error) {245 return json.Marshal(vdr)246}247// DecodeVoteReply decodes a JSON byte slice into a VoteDetailsReply.248func DecodeVoteDetailsReply(payload []byte) (*VoteDetailsReply, error) {249 var vdr VoteDetailsReply250 err := json.Unmarshal(payload, &vdr)251 if err != nil {252 return nil, err253 }254 return &vdr, nil255}256type VoteResults struct {257 Token string `json:"token"` // Censorship token258}259type VoteResultsReply struct {260 StartVote StartVote `json:"startvote"` // Original ballot261 CastVotes []CastVote `json:"castvotes"` // All votes262}263// EncodeVoteResults encodes VoteResults into a JSON byte slice.264func EncodeVoteResults(v VoteResults) ([]byte, error) {265 return json.Marshal(v)266}267// DecodeVoteResults decodes a JSON byte slice into a VoteResults.268func DecodeVoteResults(payload []byte) (*VoteResults, error) {269 var v VoteResults270 err := json.Unmarshal(payload, &v)271 if err != nil {272 return nil, err273 }274 return &v, nil275}276// EncodeVoteResultsReply encodes VoteResults into a JSON byte slice.277func EncodeVoteResultsReply(v VoteResultsReply) ([]byte, error) {278 return json.Marshal(v)279}280// DecodeVoteResultsReply decodes a JSON byte slice into a VoteResults.281func DecodeVoteResultsReply(payload []byte) (*VoteResultsReply, error) {282 var v VoteResultsReply283 err := json.Unmarshal(payload, &v)284 if err != nil {285 return nil, err286 }287 return &v, nil288}289// VoteSummary requests a summary of a proposal vote. This includes certain290// voting period parameters and a summary of the vote results.291type VoteSummary struct {292 Token string `json:"token"` // Censorship token293}294// EncodeVoteSummary encodes VoteSummary into a JSON byte slice.295func EncodeVoteSummary(v VoteSummary) ([]byte, error) {296 return json.Marshal(v)297}298// DecodeVoteSummary decodes a JSON byte slice into a VoteSummary.299func DecodeVoteSummary(payload []byte) (*VoteSummary, error) {300 var v VoteSummary301 err := json.Unmarshal(payload, &v)302 if err != nil {303 return nil, err304 }305 return &v, nil306}307// VoteOptionResult describes a vote option and the total number of votes that308// have been cast for this option.309type VoteOptionResult struct {310 ID string `json:"id"` // Single unique word identifying vote (e.g. yes)311 Description string `json:"description"` // Longer description of the vote.312 Bits uint64 `json:"bits"` // Bits used for this option313 Votes uint64 `json:"votes"` // Number of votes cast for this option314}315// VoteSummaryReply is the reply to the VoteSummary command and returns certain316// voting period parameters as well as a summary of the vote results.317type VoteSummaryReply struct {318 Authorized bool `json:"authorized"` // Vote is authorized319 EndHeight string `json:"endheight"` // End block height320 EligibleTicketCount int `json:"eligibleticketcount"` // Number of eligible tickets321 QuorumPercentage uint32 `json:"quorumpercentage"` // Percent of eligible votes required for quorum322 PassPercentage uint32 `json:"passpercentage"` // Percent of total votes required to pass323 Results []VoteOptionResult `json:"results"` // Vote results324}325// EncodeVoteSummaryReply encodes VoteSummary into a JSON byte slice.326func EncodeVoteSummaryReply(v VoteSummaryReply) ([]byte, error) {327 return json.Marshal(v)328}329// DecodeVoteSummaryReply decodes a JSON byte slice into a VoteSummaryReply.330func DecodeVoteSummaryReply(payload []byte) (*VoteSummaryReply, error) {331 var v VoteSummaryReply332 err := json.Unmarshal(payload, &v)333 if err != nil {334 return nil, err335 }336 return &v, nil337}338// Comment is the structure that describes the full server side content. It339// includes server side meta-data as well. Note that the receipt is the server340// side.341type Comment struct {342 // Data generated by client343 Token string `json:"token"` // Censorship token344 ParentID string `json:"parentid"` // Parent comment ID345 Comment string `json:"comment"` // Comment346 Signature string `json:"signature"` // Client Signature of Token+ParentID+Comment347 PublicKey string `json:"publickey"` // Pubkey used for Signature348 // Metadata generated by UtopiaCoinOrg plugin349 CommentID string `json:"commentid"` // Comment ID350 Receipt string `json:"receipt"` // Server signature of the client Signature351 Timestamp int64 `json:"timestamp"` // Received UNIX timestamp352 TotalVotes uint64 `json:"totalvotes"` // Total number of up/down votes353 ResultVotes int64 `json:"resultvotes"` // Vote score354 Censored bool `json:"censored"` // Has this comment been censored355}356// EncodeComment encodes Comment into a JSON byte slice.357func EncodeComment(c Comment) ([]byte, error) {358 return json.Marshal(c)359}360// DecodeComment decodes a JSON byte slice into a Comment361func DecodeComment(payload []byte) (*Comment, error) {362 var c Comment363 err := json.Unmarshal(payload, &c)364 if err != nil {365 return nil, err366 }367 return &c, nil368}369// NewComment sends a comment from a user to a specific proposal. Note that370// the user is implied by the session.371type NewComment struct {372 Token string `json:"token"` // Censorship token373 ParentID string `json:"parentid"` // Parent comment ID374 Comment string `json:"comment"` // Comment375 Signature string `json:"signature"` // Signature of Token+ParentID+Comment376 PublicKey string `json:"publickey"` // Pubkey used for Signature377}378// EncodeNewComment encodes NewComment into a JSON byte slice.379func EncodeNewComment(nc NewComment) ([]byte, error) {380 return json.Marshal(nc)381}382// DecodeNewComment decodes a JSON byte slice into a NewComment383func DecodeNewComment(payload []byte) (*NewComment, error) {384 var nc NewComment385 err := json.Unmarshal(payload, &nc)386 if err != nil {387 return nil, err388 }389 return &nc, nil390}391// NewCommentReply returns the metadata generated by UtopiaCoinOrg plugin for the new392// comment.393type NewCommentReply struct {394 CommentID string `json:"commentid"` // Comment ID395 Receipt string `json:"receipt"` // Server signature of the client Signature396 Timestamp int64 `json:"timestamp"` // Received UNIX timestamp397}398// EncodeNewCommentReply encodes NewCommentReply into a JSON byte slice.399func EncodeNewCommentReply(ncr NewCommentReply) ([]byte, error) {400 return json.Marshal(ncr)401}402// DecodeNewCommentReply decodes a JSON byte slice into a NewCommentReply.403func DecodeNewCommentReply(payload []byte) (*NewCommentReply, error) {404 var ncr NewCommentReply405 err := json.Unmarshal(payload, &ncr)406 if err != nil {407 return nil, err408 }409 return &ncr, nil410}411// LikeComment records an up or down vote from a user on a comment.412type LikeComment struct {413 Token string `json:"token"` // Censorship token414 CommentID string `json:"commentid"` // Comment ID415 Action string `json:"action"` // Up or downvote (1, -1)416 Signature string `json:"signature"` // Client Signature of Token+CommentID+Action417 PublicKey string `json:"publickey"` // Pubkey used for Signature418 // Only used on disk419 Receipt string `json:"receipt,omitempty"` // Signature of Signature420 Timestamp int64 `json:"timestamp,omitempty"` // Received UNIX timestamp421}422// EncodeLikeComment encodes LikeComment into a JSON byte slice.423func EncodeLikeComment(lc LikeComment) ([]byte, error) {424 return json.Marshal(lc)425}426// DecodeLikeComment decodes a JSON byte slice into a LikeComment.427func DecodeLikeComment(payload []byte) (*LikeComment, error) {428 var lc LikeComment429 err := json.Unmarshal(payload, &lc)430 if err != nil {431 return nil, err432 }433 return &lc, nil434}435// LikeCommentReply returns the result of an up or down vote.436type LikeCommentReply struct {437 Total uint64 `json:"total"` // Total number of up and down votes438 Result int64 `json:"result"` // Current tally of likes, can be negative439 Receipt string `json:"receipt"` // Server signature of client signature440 Error string `json:"error,omitempty"` // Error if something wen't wrong during liking a comment441}442// EncodeLikeCommentReply encodes LikeCommentReply into a JSON byte slice.443func EncodeLikeCommentReply(lcr LikeCommentReply) ([]byte, error) {444 return json.Marshal(lcr)445}446// DecodeLikeCommentReply decodes a JSON byte slice into a LikeCommentReply.447func DecodeLikeCommentReply(payload []byte) (*LikeCommentReply, error) {448 var lcr LikeCommentReply449 err := json.Unmarshal(payload, &lcr)450 if err != nil {451 return nil, err452 }453 return &lcr, nil454}455// CensorComment is a journal entry for a censored comment. The signature and456// public key are from the admin that censored this comment.457type CensorComment struct {458 Token string `json:"token"` // Proposal censorship token459 CommentID string `json:"commentid"` // Comment ID460 Reason string `json:"reason"` // Reason comment was censored461 Signature string `json:"signature"` // Client signature of Token+CommentID+Reason462 PublicKey string `json:"publickey"` // Pubkey used for signature463 // Generated by ucplugin464 Receipt string `json:"receipt,omitempty"` // Server signature of client signature465 Timestamp int64 `json:"timestamp,omitempty"` // Received UNIX timestamp466}467// EncodeCensorComment encodes CensorComment into a JSON byte slice.468func EncodeCensorComment(cc CensorComment) ([]byte, error) {469 return json.Marshal(cc)470}471// DecodeCensorComment decodes a JSON byte slice into a CensorComment.472func DecodeCensorComment(payload []byte) (*CensorComment, error) {473 var cc CensorComment474 err := json.Unmarshal(payload, &cc)475 if err != nil {476 return nil, err477 }478 return &cc, nil479}480// CommentCensorReply returns the receipt for the censoring action. The481// receipt is the server side signature of CommentCensor.Signature.482type CensorCommentReply struct {483 Receipt string `json:"receipt"` // Server signature of client signature484}485// EncodeCensorCommentReply encodes CensorCommentReply into a JSON byte slice.486func EncodeCensorCommentReply(ccr CensorCommentReply) ([]byte, error) {487 return json.Marshal(ccr)488}489// DecodeCensorComment decodes a JSON byte slice into a CensorCommentReply.490func DecodeCensorCommentReply(payload []byte) (*CensorCommentReply, error) {491 var ccr CensorCommentReply492 err := json.Unmarshal(payload, &ccr)493 if err != nil {494 return nil, err495 }496 return &ccr, nil497}498// GetComment retrieves a single comment. The comment can be retrieved by499// either comment ID or by signature.500type GetComment struct {501 Token string `json:"token"` // Proposal ID502 CommentID string `json:"commentid,omitempty"` // Comment ID503 Signature string `json:"signature,omitempty"` // Client signature504}505// EncodeGetComment encodes a GetComment into a JSON byte slice.506func EncodeGetComment(gc GetComment) ([]byte, error) {507 return json.Marshal(gc)508}509// DecodeGetComment decodes a JSON byte slice into a GetComment.510func DecodeGetComment(payload []byte) (*GetComment, error) {511 var gc GetComment512 err := json.Unmarshal(payload, &gc)513 if err != nil {514 return nil, err515 }516 return &gc, nil517}518// GetCommentReply returns the provided comment.519type GetCommentReply struct {520 Comment Comment `json:"comment"` // Comment521}522// EncodeGetCommentReply encodes a GetCommentReply into a JSON byte slice.523func EncodeGetCommentReply(gcr GetCommentReply) ([]byte, error) {524 return json.Marshal(gcr)525}526// DecodeGetCommentReply decodes a JSON byte slice into a GetCommentReply.527func DecodeGetCommentReply(payload []byte) (*GetCommentReply, error) {528 var gcr GetCommentReply529 err := json.Unmarshal(payload, &gcr)530 if err != nil {531 return nil, err532 }533 return &gcr, nil534}535// GetComments retrieve all comments for a given proposal. This call returns536// the cooked comments; deleted/censored comments are not returned.537type GetComments struct {538 Token string `json:"token"` // Proposal ID539}540// EncodeGetComments encodes GetCommentsReply into a JSON byte slice.541func EncodeGetComments(gc GetComments) ([]byte, error) {542 return json.Marshal(gc)543}544// DecodeGetComments decodes a JSON byte slice into a GetComments.545func DecodeGetComments(payload []byte) (*GetComments, error) {546 var gc GetComments547 err := json.Unmarshal(payload, &gc)548 if err != nil {549 return nil, err550 }551 return &gc, nil552}553// GetCommentsReply returns the provided number of comments.554type GetCommentsReply struct {555 Comments []Comment `json:"comments"` // Comments556}557// EncodeGetCommentsReply encodes GetCommentsReply into a JSON byte slice.558func EncodeGetCommentsReply(gcr GetCommentsReply) ([]byte, error) {559 return json.Marshal(gcr)560}561// DecodeGetCommentsReply decodes a JSON byte slice into a GetCommentsReply.562func DecodeGetCommentsReply(payload []byte) (*GetCommentsReply, error) {563 var gcr GetCommentsReply564 err := json.Unmarshal(payload, &gcr)565 if err != nil {566 return nil, err567 }568 return &gcr, nil569}570// GetNumComments retrieve the number of comments for a list of proposals.571type GetNumComments struct {572 Tokens []string `json:"tokens"` // Proposal ID573}574// EncodeGetNumComments encodes GetBatchComments into a JSON byte slice.575func EncodeGetNumComments(gnc GetNumComments) ([]byte, error) {576 return json.Marshal(gnc)577}578// DecodeGetNumComments decodes a JSON byte slice into a GetBatchComments.579func DecodeGetNumComments(payload []byte) (*GetNumComments, error) {580 var gnc GetNumComments581 err := json.Unmarshal(payload, &gnc)582 if err != nil {583 return nil, err584 }585 return &gnc, nil586}587// GetNumCommentsReply returns a map from proposal token to int588type GetNumCommentsReply struct {589 CommentsMap map[string]int `json:"commentsmap"`590}591// EncodeGetNumCommentsReply encodes GetNumCommentsReply into a592// JSON byte slice.593func EncodeGetNumCommentsReply(gncr GetNumCommentsReply) ([]byte, error) {594 return json.Marshal(gncr)595}596// DecodeGetNumCommentsReply decodes a JSON byte slice into a597// GetNumCommentsReply.598func DecodeGetNumCommentsReply(payload []byte) (*GetNumCommentsReply, error) {599 var gncr GetNumCommentsReply600 err := json.Unmarshal(payload, &gncr)601 if err != nil {602 return nil, err603 }604 return &gncr, nil605}606// CommentLikes is used to retrieve all of the comment likes for a single607// record comment.608type CommentLikes struct {609 Token string `json:"token"` // Censorship token610 CommentID string `json:"commentid"` // Comment ID611}612// EncodeCommentLikes encodes CommentLikes into a JSON byte slice.613func EncodeCommentLikes(gpcv CommentLikes) ([]byte, error) {614 return json.Marshal(gpcv)615}616// DecodeCommentLikes decodes a JSON byte slice into a CommentLikes.617func DecodeCommentLikes(payload []byte) (*CommentLikes, error) {618 var cl CommentLikes619 err := json.Unmarshal(payload, &cl)620 if err != nil {621 return nil, err622 }623 return &cl, nil624}625// CommentLikesReply is the reply to CommentLikes and returns all of the626// upvote/downvote actions for the specified comment.627type CommentLikesReply struct {628 CommentLikes []LikeComment `json:"commentlikes"`629}630// EncodeCommentLikesReply encodes EncodeCommentLikesReply into a JSON byte631// slice.632func EncodeCommentLikesReply(clr CommentLikesReply) ([]byte, error) {633 return json.Marshal(clr)634}635// DecodeCommentLikesReply decodes a JSON byte slice into a CommentLikesReply.636func DecodeCommentLikesReply(payload []byte) (*CommentLikesReply, error) {637 var clr CommentLikesReply638 err := json.Unmarshal(payload, &clr)639 if err != nil {640 return nil, err641 }642 return &clr, nil643}644// GetProposalCommentsLikes is a command to fetch all vote actions645// on the comments of a given proposal646type GetProposalCommentsLikes struct {647 Token string `json:"token"` // Censorship token648}649// EncodeGetProposalCommentsLikes encodes GetProposalCommentsLikes into a JSON byte slice.650func EncodeGetProposalCommentsLikes(gpcv GetProposalCommentsLikes) ([]byte, error) {651 return json.Marshal(gpcv)652}653// DecodeGetProposalCommentsLikes decodes a JSON byte slice into a GetProposalCommentsLikes.654func DecodeGetProposalCommentsLikes(payload []byte) (*GetProposalCommentsLikes, error) {655 var gpcl GetProposalCommentsLikes656 err := json.Unmarshal(payload, &gpcl)657 if err != nil {658 return nil, err659 }660 return &gpcl, nil661}662// GetProposalCommentsLikesReply is a reply with all vote actions663// for the comments of a given proposal664type GetProposalCommentsLikesReply struct {665 CommentsLikes []LikeComment `json:"commentslikes"`666}667// EncodeGetProposalCommentsLikesReply encodes EncodeGetProposalCommentsLikesReply into a JSON byte slice.668func EncodeGetProposalCommentsLikesReply(gpclr GetProposalCommentsLikesReply) ([]byte, error) {669 return json.Marshal(gpclr)670}671// DecodeGetProposalCommentsLikesReply decodes a JSON byte slice into a GetProposalCommentsLikesReply.672func DecodeGetProposalCommentsLikesReply(payload []byte) (*GetProposalCommentsLikesReply, error) {673 var gpclr GetProposalCommentsLikesReply674 err := json.Unmarshal(payload, &gpclr)675 if err != nil {676 return nil, err677 }678 return &gpclr, nil679}680// Inventory is used to retrieve the UtopiaCoinOrg plugin inventory.681type Inventory struct{}682// EncodeInventory encodes Inventory into a JSON byte slice.683func EncodeInventory(i Inventory) ([]byte, error) {684 return json.Marshal(i)685}686// DecodeInventory decodes a JSON byte slice into a Inventory.687func DecodeInventory(payload []byte) (*Inventory, error) {688 var i Inventory689 err := json.Unmarshal(payload, &i)690 if err != nil {691 return nil, err692 }693 return &i, nil694}695// StartVoteTuple is used to return the StartVote and StartVoteReply for a696// record. StartVoteReply does not contain any record identifying data so it697// must be returned with the StartVote in order to know what record it belongs698// to.699type StartVoteTuple struct {700 StartVote StartVote `json:"startvote"` // Start vote701 StartVoteReply StartVoteReply `json:"startvotereply"` // Start vote reply702}703// InventoryReply returns the UtopiaCoinOrg plugin inventory.704type InventoryReply struct {705 Comments []Comment `json:"comments"` // Comments706 LikeComments []LikeComment `json:"likecomments"` // Like comments707 AuthorizeVotes []AuthorizeVote `json:"authorizevotes"` // Authorize votes708 AuthorizeVoteReplies []AuthorizeVoteReply `json:"authorizevotereplies"` // Authorize vote replies709 StartVoteTuples []StartVoteTuple `json:"startvotetuples"` // Start vote tuples710 CastVotes []CastVote `json:"castvotes"` // Cast votes711}712// EncodeInventoryReply encodes a InventoryReply into a JSON byte slice.713func EncodeInventoryReply(ir InventoryReply) ([]byte, error) {714 return json.Marshal(ir)715}716// DecodeInventoryReply decodes a JSON byte slice into a inventory.717func DecodeInventoryReply(payload []byte) (*InventoryReply, error) {718 var ir InventoryReply719 err := json.Unmarshal(payload, &ir)720 if err != nil {721 return nil, err722 }723 return &ir, nil...
activity.go
Source:activity.go
...6type CActivity struct {7 ID int64 `json:"id"`8 Name string `json:"name" form:"name" validate:"required"`9 Creator string `json:"creator"`10 SignedStart time.Time `json:"signed_start" form:"signed_start" validate:"required"`11 SignedEnd time.Time `json:"signed_end" form:"signed_end" validate:"required"`12 SignUp int `json:"sign_up" form:"sign_up" default:"0"` // éè¦æ¥å 0ä¸éè¦,1éè¦13 SignUpStart time.Time `json:"sign_up_start" form:"sign_up_start" validate:"required"`14 SignUpEnd time.Time `json:"sign_up_end" form:"sign_up_end" validate:"required"`15 Object int `json:"object" form:"object" validate:"required"` // 1:uid, 2:avid16 UploadStart time.Time `json:"upload_start" form:"upload_start" validate:"required"`17 UploadEnd time.Time `json:"upload_end" form:"upload_end" validate:"required"`18 WinType int `json:"win_type" form:"win_type" validate:"required"` // 1:è¾¾æ å,2:æåºå19 RequireItems string `json:"require_items" form:"require_items" validate:"required"` // 1:ç¹èµ,2:å享,3:ææ¾,4:è¯è®º,5:å¼¹å¹, å¤ä¸ªç¨","åå²20 RequireValue int64 `json:"require_value" form:"require_value" validate:"required"`21 StatisticsStart time.Time `json:"statistics_start" form:"statistics_start" validate:"required"`22 StatisticsEnd time.Time `json:"statistics_end" form:"statistics_end" validate:"required"`23 BonusType int `json:"bonus_type" form:"bonus_type" validate:"required"` // 1:å¹³å,2:åå¾24 BonusMoney []int64 `json:"bonus_money" form:"bonus_money,split" validate:"required"` // (å¤ä¸ª","åå²)25 BonusTime time.Time `json:"bonus_time" form:"bonus_time" validate:"required"`26 ProgressFrequency int `json:"progress_frequency" form:"progress_frequency" validate:"required"` // è¿å±æ´æ°é¢ç 1:æ¯å¤© 2:æ¯å¨27 UpdatePage int `json:"update_page" form:"update_page" default:"0"` // æ´æ°æ´»å¨é¡µ 0:å¦ 1:æ¯28 ProgressStart time.Time `json:"progress_start" form:"progress_start" validate:"required"`29 ProgressEnd time.Time `json:"progress_end" form:"progress_end" validate:"required"`30 ProgressSync int `json:"progress_sync" form:"progress_sync" default:"0"` // è¿å±åæ¥ 1å
±æ,2å·²æ,3å
±æ/å·²æ31 BonusQuery int `json:"bonus_query" form:"bonus_query" default:"0"` // å¼å¥æ¥è¯¢ 0:å¦ 1:æ¯32 BonusQuerStart time.Time `json:"bonus_query_start" form:"bonus_query_start" validate:"required"`33 BonusQueryEnd time.Time `json:"bonus_query_end" form:"bonus_query_end" validate:"required"`34 Background string `json:"background" form:"background" validate:"required"`35 WinDesc string `json:"win_desc" form:"win_desc" validate:"required"`36 UnwinDesc string `json:"unwin_desc" form:"unwin_desc" validate:"required"`37 Details string `json:"details" form:"details" validate:"required"`38 State int `json:"state"` // æ´»å¨ç¶æ 0æªå¼å§,1å·²å¼å§,2å·²ç»æ39 Enrolment int `json:"enrolment"` // æ¥å人æ°40 WinNum int `json:"win_num"` // ä¸å¥äººæ°41}42// BonusRank bonus rank43type BonusRank struct {44 ID int6445 Rank int46 Money int64...
meeting.go
Source:meeting.go
...40 db.Table("meetings").Where("UUid = ?", meeting.UUid).Delete(&meeting)41 //å é¤SmartMeeting表信æ¯42 db.Table(meeting.ReturnDate).Where("meeting_u_uid = ? and user_phone_number = ?", meeting.MeetingUUid,43 meeting.PhoneNumber).Delete(module.SmartMeeting{})44 db.Table(meeting.StartDate).Where("meeting_u_uid = ? and user_phone_number = ?", meeting.MeetingUUid,45 meeting.PhoneNumber).Delete(module.SmartMeeting{})46 //å é¤Orderä¿¡æ¯47 var order module.Order48 db.Table("orders").Where("user_phone = ? and user_name = ?", meeting.PhoneNumber,49 meeting.Name).Find(&order)50 db.Table("orders").Where("user_phone = ? and user_name = ?", meeting.PhoneNumber,51 meeting.Name).Delete(&order)52 //æ´æ°å¸æºä¿¡æ¯53 db.Table("drivers").Where("u_uid = ?", order.DriverUUid).Update("status_now", constant.DRIVER_READY)54 //æ´æ°Meetingä¿¡æ¯55 meeting.UUid = json["UUid"].(string)56 meeting.Name = json["Name"].(string)57 meeting.PhoneNumber = json["PhoneNumber"].(string)58 meeting.StartDate = json["StartDate"].(string)59 meeting.StartTime = json["StartTime"].(string)60 meeting.StartBeginAddress = json["StartBeginAddress"].(string)61 meeting.StartEndAddress = json["StartEndAddress"].(string)62 meeting.StartShift = json["StartShift"].(string)63 meeting.ReturnDate = json["ReturnDate"].(string)64 meeting.ReturnTime = json["ReturnTime"].(string)65 meeting.ReturnStartAddress = json["ReturnStartAddress"].(string)66 meeting.ReturnEndAddress = json["ReturnEndAddress"].(string)67 meeting.ReturnShift = json["ReturnShift"].(string)68 meeting.IfSolve = 069 //å°æ´æ°åçä¿¡æ¯ä¿åçDB70 db.Table("meetings").Where("UUid = ?", meeting.UUid).Save(&meeting)71 return nil72}...
Start
Using AI Code Generation
1import (2type Person struct {3}4func main() {5 rdr := strings.NewReader(`{"First":"James", "Last":"Bond", "Age":20}`)6 json.NewDecoder(rdr).Decode(&p1)7 fmt.Println(p1.First)8 fmt.Println(p1.Last)9 fmt.Println(p1.Age)10}11import (12type Person struct {13}14func main() {15 rdr := strings.NewReader(`{"First":"James", "Last":"Bond", "Age":20}`)16 json.NewDecoder(rdr).Decode(&p1)17 fmt.Println(p1.First)18 fmt.Println(p1.Last)19 fmt.Println(p1.Age)20}21import (22type Person struct {23}24func main() {25 rdr := strings.NewReader(`{"First":"James", "Last":"Bond", "Age":20}`)26 json.NewDecoder(rdr).Decode(&p1)27 fmt.Println(p1.First)28 fmt.Println(p1.Last)29 fmt.Println(p1.Age)30}31import (32type Person struct {33}34func main() {35 rdr := strings.NewReader(`{"First":"James", "Last":"Bond", "Age":20}`)36 json.NewDecoder(rdr).Decode(&p1)37 fmt.Println(p1.First)38 fmt.Println(p1.Last)39 fmt.Println(p1.Age)40}41import (42type Person struct {43}44func main() {45 rdr := strings.NewReader(`{"First":"James", "Last":"Bond", "Age":
Start
Using AI Code Generation
1import (2type Person struct {3}4func main() {5 p1 := Person{"James", 20}6 bs, _ := json.Marshal(p1)7 fmt.Println(bs)8 fmt.Printf("%T9 fmt.Println(string(bs))10}11{"Name":"James","Age":20}12import (13type Person struct {14}15func main() {16 p1 := Person{"James", 20}17 bs, _ := json.Marshal(p1)18 fmt.Println(bs)19 fmt.Printf("%T20 fmt.Println(string(bs))21}22{"Name":"James","Age":20}23import (24type Person struct {25}26func main() {27 p1 := Person{"James", 20}28 bs, _ := json.Marshal(p1)29 fmt.Println(bs)30 fmt.Printf("%T31 fmt.Println(string(bs))32}33{"Name":"James","Age":20}34import (35type Person struct {36}37func main() {38 p1 := Person{"James", 20}
Start
Using AI Code Generation
1import (2type Person struct {3}4func main() {5 p1 := Person{"James", "Bond", 20}6 bs, _ := json.Marshal(p1)7 fmt.Println(bs)8 fmt.Printf("%T9 fmt.Println(string(bs))10}11{"First":"James","Last":"Bond","Age":20}12import (13type Person struct {14}15func main() {16 p1 := Person{"James", "Bond", 20}17 bs, _ := json.Marshal(p1)18 fmt.Println(bs)19 fmt.Printf("%T20 fmt.Println(string(bs))21}22{"First":"James","Last":"Bond","Age":20}23import (24type Person struct {25}26func main() {27 p1 := Person{"James", "Bond", 20}28 bs, _ := json.Marshal(p1)29 fmt.Println(bs)30 fmt.Printf("%T31 fmt.Println(string(bs))32}
Start
Using AI Code Generation
1import (2func main() {3 jsonFile, err := os.Open("data.json")4 if err != nil {5 fmt.Println(err)6 }7 fmt.Println("Successfully Opened users.json")8 defer jsonFile.Close()9 byteValue, _ := ioutil.ReadAll(jsonFile)10 json.Unmarshal(byteValue, &users)11 for i := 0; i < len(users.Users); i++ {12 fmt.Println("User Type: " + users.Users[i].Type)13 fmt.Println("Name: " + users.Users[i].Name)14 fmt.Println("Facebook Url: " + users.Users[i].Facebook)15 fmt.Println("")16 }17}18import (19func main() {20 jsonFile, err := os.Open("data.json")21 if err != nil {22 fmt.Println(err)23 }24 fmt.Println("Successfully Opened users.json")25 defer jsonFile.Close()26 byteValue, _ := ioutil.ReadAll(jsonFile)27 json.Unmarshal(byteValue, &users)28 for i := 0; i < len(users.Users); i++ {29 fmt.Println("User Type: " + users.Users[i].Type)
Start
Using AI Code Generation
1import "encoding/json"2import "fmt"3type Person struct {4}5func main() {6 p1 := Person{"James", "Bond", 20}7 p2 := Person{"Miss", "Moneypenny", 19}8 people := []Person{p1, p2}9 fmt.Println(people)10 bs, _ := json.Marshal(people)11 fmt.Println(bs)12 fmt.Println(string(bs))13}14import "encoding/json"15import "fmt"16type Person struct {17}18func main() {19 p1 := Person{"James", "Bond", 20}20 p2 := Person{"Miss", "Moneypenny", 19}21 people = append(people, p1)22 people = append(people, p2)23 fmt.Println(people)24 bs, _ := json.Marshal(people)25 fmt.Println(bs)26 fmt.Println(string(bs))27}28import "encoding/json"29import "fmt"30type Person struct {31}32func main() {33 p1 := Person{"James", "Bond", 20}34 p2 := Person{"Miss", "Moneypenny", 19}35 people = append(people, p1)36 people = append(people, p2)37 fmt.Println(people)38 bs, _ := json.Marshal(people)39 fmt.Println(bs)40 fmt.Println(string(bs))41}42import "encoding/json"43import "fmt"44type Person struct {45}46func main() {47 p1 := Person{"James", "Bond", 20}48 p2 := Person{"Miss", "Moneypenny", 19}49 people = append(people, p1)50 people = append(people, p2)51 fmt.Println(people)52 bs, _ := json.Marshal(people)53 fmt.Println(bs)
Start
Using AI Code Generation
1import (2func main() {3 type Person struct {4 }5 p1 := Person{"John", 30}6 p2 := Person{"Alex", 40}7 p3 := Person{"Bob", 50}8 people := []Person{p1, p2, p3}9 fmt.Println(people)10 jsonPeople, _ := json.Marshal(people)11 fmt.Println(string(jsonPeople))12}13[{John 30} {Alex 40} {Bob 50}]14[{"Name":"John","Age":30},{"Name":"Alex","Age":40},{"Name":"Bob","Age":50}]15import (16func main() {17 type Person struct {18 }19 jsonPeople := []byte(`[{"Name":"John","Age":30},{"Name":"Alex","Age":40},{"Name":"Bob","Age":50}]`)20 json.Unmarshal(jsonPeople, &people)21 fmt.Println(people)22}23[{John 30} {Alex 40} {Bob 50}]24import (25func main() {26 type Person struct {27 }28 p1 := Person{"John", 30}29 p2 := Person{"Alex", 40}30 p3 := Person{"Bob", 50}31 people := []Person{p1, p2, p3}32 fmt.Println(people)33 jsonPeople, _ := json.MarshalIndent(people, "", " ")34 fmt.Println(string(jsonPeople))35}36[{John 30} {Alex 40} {Bob 50}]37 {38 },39 {40 },41 {42 }
Start
Using AI Code Generation
1import (2func main() {3 var jsonString = []byte(`{4 }`)5 var data map[string]interface{}6 json.Unmarshal(jsonString, &data)7 fmt.Println(data)8}9import (10type Person struct {11}12func main() {13 var jsonString = []byte(`{14 }`)15 var data map[string]interface{}16 json.Unmarshal(jsonString, &data)17 fmt.Println(data)18 json.Unmarshal(jsonString, &person)19 fmt.Println(person)20}21{John 30 New York}22import (23type Person struct {24}25func main() {26 var jsonString = []byte(`{27 }`)28 var data map[string]interface{}29 json.Unmarshal(jsonString, &data)30 fmt.Println(data
Start
Using AI Code Generation
1import (2func main() {3 type person struct {4 }5 p1 := person{Name: "John", Age: 30}6 data, err = json.Marshal(p1)7 if err != nil {8 fmt.Println("Error in marshalling")9 }10 fmt.Println(string(data))11}12{"Name":"John","Age":30}13import (14func main() {15 type person struct {16 }17 p1 := person{Name: "John", Age: 30}18 data, err = json.MarshalIndent(p1, "", " ")19 if err != nil {20 fmt.Println("Error in marshalling")21 }22 fmt.Println(string(data))23}24{25}26import (27func main() {28 type person struct {29 }30 p1 := person{Name: "John", Age: 30}31 data, err = json.Marshal(p1)32 if err != nil {33 fmt.Println("Error in marshalling")34 }35 fmt.Println(string(data))36 err = json.Unmarshal(data, &p2)37 if err != nil {38 fmt.Println("Error in unmarshalling")39 }40 fmt.Println(p2)41}42{"Name":"John","Age":30}43{John 30}
Start
Using AI Code Generation
1import (2func main() {3 countryCapitalMap := map[string]interface{}{4 }5 jsonFile, err := json.MarshalIndent(countryCapitalMap, "", " ")6 if err != nil {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!