How to use UnmarshalJSON method of v1 Package

Best K6 code snippet using v1.UnmarshalJSON

activity.go

Source:activity.go Github

copy

Full Screen

...49 Data json.RawMessage `json:"data"`50 } `json:"actor"`51 } `json:"relationships"`52}53// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.54func (a *Activity) UnmarshalJSON(b []byte) error {55 var helper activityUnmarshalHelper56 helper.Attributes = &helper.activity57 if err := json.Unmarshal(b, &helper); err != nil {58 return err59 }60 *a = Activity(helper.activity)61 a.Attachments = helper.Relationships.Attachments.Data62 a.RawActor = helper.Relationships.RawActor.Data63 a.rawData = b64 return nil65}66// Actor returns returns the parsed actor. For recognized actor types, a value of the corresponding struct type will be returned.67func (a *Activity) Actor() (actor interface{}) {68 var obj unknownResource69 if err := json.Unmarshal(a.RawActor, &obj); err != nil {70 panic(err.Error())71 }72 switch *obj.Type {73 case UserType:74 actor = &User{}75 case ProgramType:76 actor = &Program{}77 }78 if err := json.Unmarshal(a.RawActor, &actor); err != nil {79 panic(err.Error())80 }81 return actor82}83// Activity returns the parsed activity. For recognized activity types, a value of the corresponding struct type will be returned.84func (a *Activity) Activity() (activity interface{}) {85 switch *a.Type {86 case ActivityBountyAwardedType:87 activity = &ActivityBountyAwarded{}88 case ActivityBountySuggestedType:89 activity = &ActivityBountySuggested{}90 case ActivityBugClonedType:91 activity = &ActivityBugCloned{}92 case ActivityExternalUserInvitationCancelledType:93 activity = &ActivityExternalUserInvitationCancelled{}94 case ActivityExternalUserInvitedType:95 activity = &ActivityExternalUserInvited{}96 case ActivityExternalUserJoinedType:97 activity = &ActivityExternalUserJoined{}98 case ActivityExternalUserRemovedType:99 activity = &ActivityExternalUserRemoved{}100 case ActivityGroupAssignedToBugType:101 activity = &ActivityGroupAssignedToBug{}102 case ActivityReferenceIDAddedType:103 activity = &ActivityReferenceIDAdded{}104 case ActivityReportTitleUpdatedType:105 activity = &ActivityReportTitleUpdated{}106 case ActivityReportVulnerabilityTypesUpdatedType:107 activity = &ActivityReportVulnerabilityTypesUpdated{}108 case ActivitySwagAwardedType:109 activity = &ActivitySwagAwarded{}110 case ActivityUserAssignedToBugType:111 activity = &ActivityUserAssignedToBug{}112 case ActivityUserBannedFromProgramType:113 activity = &ActivityUserBannedFromProgram{}114 default:115 return nil116 }117 if err := json.Unmarshal(a.rawData, activity); err != nil {118 panic(err.Error())119 }120 return activity121}122// Report returns the report this activity is a child of123func (a *Activity) Report() *Report {124 return a.report125}126// ActivityBountyAwarded occurs when a bounty is awarded.127//128// HackerOne API docs:https://api.hackerone.com/docs/v1#activity-bounty-awarded129type ActivityBountyAwarded struct {130 BountyAmount *string `json:"bounty_amount"`131 BonusAmount *string `json:"bonus_amount"`132}133// Helper types for JSONUnmarshal134type activityBountyAwarded ActivityBountyAwarded // Used to avoid recursion of JSONUnmarshal135type activityBountyAwardedUnmarshalHelper struct {136 Attributes activityBountyAwarded `json:"attributes"`137}138// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.139func (a *ActivityBountyAwarded) UnmarshalJSON(b []byte) error {140 var helper activityBountyAwardedUnmarshalHelper141 if err := json.Unmarshal(b, &helper); err != nil {142 return err143 }144 *a = ActivityBountyAwarded(helper.Attributes)145 return nil146}147// ActivityBountySuggested occurs when a bounty is suggested.148//149// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-bounty-suggested150type ActivityBountySuggested struct {151 BountyAmount *string `json:"bounty_amount"`152 BonusAmount *string `json:"bonus_amount"`153}154// Helper types for JSONUnmarshal155type activityBountySuggested ActivityBountySuggested // Used to avoid recursion of JSONUnmarshal156type activityBountySuggestedUnmarshalHelper struct {157 Attributes activityBountySuggested `json:"attributes"`158}159// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.160func (a *ActivityBountySuggested) UnmarshalJSON(b []byte) error {161 var helper activityBountySuggestedUnmarshalHelper162 if err := json.Unmarshal(b, &helper); err != nil {163 return err164 }165 *a = ActivityBountySuggested(helper.Attributes)166 return nil167}168// ActivityBugCloned occurs when a bug is cloned.169//170// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-bug-cloned171type ActivityBugCloned struct {172 OriginalReportID *int `json:"original_report_id"`173}174// Helper types for JSONUnmarshal175type activityBugCloned ActivityBugCloned // Used to avoid recursion of JSONUnmarshal176type activityBugClonedUnmarshalHelper struct {177 Attributes activityBugCloned `json:"attributes"`178}179// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.180func (a *ActivityBugCloned) UnmarshalJSON(b []byte) error {181 var helper activityBugClonedUnmarshalHelper182 if err := json.Unmarshal(b, &helper); err != nil {183 return err184 }185 *a = ActivityBugCloned(helper.Attributes)186 return nil187}188// ActivityExternalUserInvitationCancelled occurs when a external user's invitiation is cancelled.189//190// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-external-user-invitation-cancelled191type ActivityExternalUserInvitationCancelled struct {192 Email *string `json:"email"`193}194// Helper types for JSONUnmarshal195type activityExternalUserInvitationCancelled ActivityExternalUserInvitationCancelled // Used to avoid recursion of JSONUnmarshal196type activityExternalUserInvitationCancelledSuggestedUnmarshalHelper struct {197 Attributes activityExternalUserInvitationCancelled `json:"attributes"`198}199// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.200func (a *ActivityExternalUserInvitationCancelled) UnmarshalJSON(b []byte) error {201 var helper activityExternalUserInvitationCancelledSuggestedUnmarshalHelper202 if err := json.Unmarshal(b, &helper); err != nil {203 return err204 }205 *a = ActivityExternalUserInvitationCancelled(helper.Attributes)206 return nil207}208// ActivityExternalUserInvited occurs when a external user is invited.209//210// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-external-user-invited211type ActivityExternalUserInvited struct {212 Email *string `json:"email"`213}214// Helper types for JSONUnmarshal215type activityExternalUserInvited ActivityExternalUserInvited // Used to avoid recursion of JSONUnmarshal216type activityExternalUserInvitedUnmarshalHelper struct {217 Attributes activityExternalUserInvited `json:"attributes"`218}219// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.220func (a *ActivityExternalUserInvited) UnmarshalJSON(b []byte) error {221 var helper activityExternalUserInvitedUnmarshalHelper222 if err := json.Unmarshal(b, &helper); err != nil {223 return err224 }225 *a = ActivityExternalUserInvited(helper.Attributes)226 return nil227}228// ActivityExternalUserJoined occurs when a external user joins.229//230// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-external-user-joined231type ActivityExternalUserJoined struct {232 DuplicateReportID *int `json:"duplicate_report_id"`233}234// Helper types for JSONUnmarshal235type activityExternalUserJoined ActivityExternalUserJoined // Used to avoid recursion of JSONUnmarshal236type activityExternalUserJoinedUnmarshalHelper struct {237 Attributes activityExternalUserJoined `json:"attributes"`238}239// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.240func (a *ActivityExternalUserJoined) UnmarshalJSON(b []byte) error {241 var helper activityExternalUserJoinedUnmarshalHelper242 if err := json.Unmarshal(b, &helper); err != nil {243 return err244 }245 *a = ActivityExternalUserJoined(helper.Attributes)246 return nil247}248// ActivityExternalUserRemoved occurs when a external user is removed249//250// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-external-user-removed251type ActivityExternalUserRemoved struct {252 RemovedUser *User `json:"removed_user"`253}254// Helper types for JSONUnmarshal255type activityExternalUserRemoved ActivityExternalUserRemoved // Used to avoid recursion of JSONUnmarshal256type activityExternalUserRemovedUnmarshalHelper struct {257 Relationships struct {258 RemovedUser struct {259 Data *User `json:"data"`260 } `json:"removed_user"`261 } `json:"relationships"`262}263// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.264func (a *ActivityExternalUserRemoved) UnmarshalJSON(b []byte) error {265 var helper activityExternalUserRemovedUnmarshalHelper266 if err := json.Unmarshal(b, &helper); err != nil {267 return err268 }269 a.RemovedUser = helper.Relationships.RemovedUser.Data270 return nil271}272// ActivityGroupAssignedToBug occurs when a group is assigned to a report.273//274// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-group-assigned-to-bug275type ActivityGroupAssignedToBug struct {276 Group *Group `json:"group"`277}278// Helper types for JSONUnmarshal279type activityGroupAssignedToBug ActivityGroupAssignedToBug // Used to avoid recursion of JSONUnmarshal280type activityGroupAssignedToBugUnmarshalHelper struct {281 Relationships struct {282 Group struct {283 Data *Group `json:"data"`284 } `json:"group"`285 } `json:"relationships"`286}287// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.288func (a *ActivityGroupAssignedToBug) UnmarshalJSON(b []byte) error {289 var helper activityGroupAssignedToBugUnmarshalHelper290 if err := json.Unmarshal(b, &helper); err != nil {291 return err292 }293 a.Group = helper.Relationships.Group.Data294 return nil295}296// ActivityReferenceIDAdded occurs when a reference id/url is added to a report.297//298// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-reference-id-added299type ActivityReferenceIDAdded struct {300 Reference *string `json:"reference"`301 ReferenceURL *string `json:"reference_url"`302}303// Helper types for JSONUnmarshal304type activityReferenceIDAdded ActivityReferenceIDAdded // Used to avoid recursion of JSONUnmarshal305type activityReferenceIDAddedUnmarshalHelper struct {306 Attributes activityReferenceIDAdded `json:"attributes"`307}308// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.309func (a *ActivityReferenceIDAdded) UnmarshalJSON(b []byte) error {310 var helper activityReferenceIDAddedUnmarshalHelper311 if err := json.Unmarshal(b, &helper); err != nil {312 return err313 }314 *a = ActivityReferenceIDAdded(helper.Attributes)315 return nil316}317// ActivityReportTitleUpdated occurs when report title is updated318//319// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-report-title-updated320type ActivityReportTitleUpdated struct {321 OldTitle *string `json:"old_title"`322 NewTitle *string `json:"new_title"`323}324// Helper types for JSONUnmarshal325type activityReportTitleUpdated ActivityReportTitleUpdated // Used to avoid recursion of JSONUnmarshal326type activityReportTitleUpdatedUnmarshalHelper struct {327 Attributes activityReportTitleUpdated `json:"attributes"`328}329// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.330func (a *ActivityReportTitleUpdated) UnmarshalJSON(b []byte) error {331 var helper activityReportTitleUpdatedUnmarshalHelper332 if err := json.Unmarshal(b, &helper); err != nil {333 return err334 }335 *a = ActivityReportTitleUpdated(helper.Attributes)336 return nil337}338// ActivityReportVulnerabilityTypesUpdated occurs when vulnerability types for a report are updated.339//340// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-report-vulnerability-types-updated341type ActivityReportVulnerabilityTypesUpdated struct {342 OldVulnerabilityTypes []VulnerabilityType `json:"old_vulnerability_types"`343 NewVulnerabilityTypes []VulnerabilityType `json:"new_vulnerability_types"`344}345// Helper types for JSONUnmarshal346type activityReportVulnerabilityTypesUpdated ActivityReportVulnerabilityTypesUpdated // Used to avoid recursion of JSONUnmarshal347type activityReportVulnerabilityTypesUpdatedUnmarshalHelper struct {348 Relationships struct {349 OldVulnerabilityTypes struct {350 Data []VulnerabilityType `json:"data"`351 } `json:"old_vulnerability_types"`352 NewVulnerabilityTypes struct {353 Data []VulnerabilityType `json:"data"`354 } `json:"new_vulnerability_types"`355 } `json:"relationships"`356}357// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.358func (a *ActivityReportVulnerabilityTypesUpdated) UnmarshalJSON(b []byte) error {359 var helper activityReportVulnerabilityTypesUpdatedUnmarshalHelper360 if err := json.Unmarshal(b, &helper); err != nil {361 return err362 }363 a.OldVulnerabilityTypes = helper.Relationships.OldVulnerabilityTypes.Data364 a.NewVulnerabilityTypes = helper.Relationships.NewVulnerabilityTypes.Data365 return nil366}367// ActivitySwagAwarded occurs when swag is awarded368//369// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-swag-awarded370type ActivitySwagAwarded struct {371 Swag *Swag `json:"swag"`372}373// Helper types for JSONUnmarshal374type activitySwagAwarded ActivitySwagAwarded // Used to avoid recursion of JSONUnmarshal375type activitySwagAwardedUnmarshalHelper struct {376 Relationships struct {377 Swag struct {378 Data *Swag `json:"data"`379 } `json:"swag"`380 } `json:"relationships"`381}382// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.383func (a *ActivitySwagAwarded) UnmarshalJSON(b []byte) error {384 var helper activitySwagAwardedUnmarshalHelper385 if err := json.Unmarshal(b, &helper); err != nil {386 return err387 }388 a.Swag = helper.Relationships.Swag.Data389 return nil390}391// ActivityUserAssignedToBug occurs when a user is assigned to a report.392//393// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-user-assigned-to-bug394type ActivityUserAssignedToBug struct {395 AssignedUser *User `json:"assigned_user"`396}397// Helper types for JSONUnmarshal398type activityUserAssignedToBug ActivityUserAssignedToBug // Used to avoid recursion of JSONUnmarshal399type activityUserAssignedToBugUnmarshalHelper struct {400 Relationships struct {401 AssignedUser struct {402 Data *User `json:"data"`403 } `json:"assigned_user"`404 } `json:"relationships"`405}406// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.407func (a *ActivityUserAssignedToBug) UnmarshalJSON(b []byte) error {408 var helper activityUserAssignedToBugUnmarshalHelper409 if err := json.Unmarshal(b, &helper); err != nil {410 return err411 }412 a.AssignedUser = helper.Relationships.AssignedUser.Data413 return nil414}415// ActivityUserBannedFromProgram occurs when a user is banned from a program.416//417// HackerOne API docs: https://api.hackerone.com/docs/v1#activity-user-banned-from-program418type ActivityUserBannedFromProgram struct {419 RemovedUser *User `json:"removed_user"`420}421// Helper types for JSONUnmarshal422type activityUserBannedFromProgram ActivityUserBannedFromProgram // Used to avoid recursion of JSONUnmarshal423type activityUserBannedFromProgramUnmarshalHelper struct {424 Relationships struct {425 RemovedUser struct {426 Data *User `json:"data"`427 } `json:"removed_user"`428 } `json:"relationships"`429}430// UnmarshalJSON allows JSONAPI attributes and relationships to unmarshal cleanly.431func (a *ActivityUserBannedFromProgram) UnmarshalJSON(b []byte) error {432 var helper activityUserBannedFromProgramUnmarshalHelper433 if err := json.Unmarshal(b, &helper); err != nil {434 return err435 }436 a.RemovedUser = helper.Relationships.RemovedUser.Data437 return nil438}...

Full Screen

Full Screen

account_json.go

Source:account_json.go Github

copy

Full Screen

...35 }36 switch key {37 case "start":38 if data := in.Raw(); in.Ok() {39 in.AddError((out.Start).UnmarshalJSON(data))40 }41 case "finish":42 if data := in.Raw(); in.Ok() {43 in.AddError((out.Finish).UnmarshalJSON(data))44 }45 default:46 in.SkipRecursive()47 }48 in.WantComma()49 }50 in.Delim('}')51 if isTopLevel {52 in.Consumed()53 }54}55// UnmarshalJSON supports json.Unmarshaler interface56func (v *PremiumInterval) UnmarshalJSON(data []byte) error {57 r := jlexer.Lexer{Data: data}58 decodePremium(&r, v)59 return r.Error()60}61func decodeOneLike(in *jlexer.Lexer, out *OneLike) {62 isTopLevel := in.IsStart()63 if in.IsNull() {64 if isTopLevel {65 in.Consumed()66 }67 in.Skip()68 return69 }70 in.Delim('{')71 for !in.IsDelim('}') {72 key := in.UnsafeString()73 in.WantColon()74 if in.IsNull() {75 in.Skip()76 in.WantComma()77 continue78 }79 switch key {80 case "id":81 out.ID = uint32(in.Uint32())82 case "ts":83 if data := in.Raw(); in.Ok() {84 in.AddError((out.Stamp).UnmarshalJSON(data))85 }86 default:87 in.SkipRecursive()88 }89 in.WantComma()90 }91 in.Delim('}')92 if isTopLevel {93 in.Consumed()94 }95}96// UnmarshalJSON supports json.Unmarshaler interface97func (v *OneLike) UnmarshalJSON(data []byte) error {98 r := jlexer.Lexer{Data: data}99 decodeOneLike(&r, v)100 return r.Error()101}102func decodeAccounts(in *jlexer.Lexer, out *Accounts) {103 isTopLevel := in.IsStart()104 if in.IsNull() {105 if isTopLevel {106 in.Consumed()107 }108 in.Skip()109 return110 }111 in.Delim('{')112 for !in.IsDelim('}') {113 key := in.UnsafeString()114 in.WantColon()115 if in.IsNull() {116 in.Skip()117 in.WantComma()118 continue119 }120 switch key {121 case "accounts":122 if in.IsNull() {123 in.Skip()124 out.Accounts = nil125 } else {126 in.Delim('[')127 if out.Accounts == nil {128 if !in.IsDelim(']') {129 out.Accounts = make([]Account, 0, 1)130 } else {131 out.Accounts = []Account{}132 }133 } else {134 out.Accounts = (out.Accounts)[:0]135 }136 for !in.IsDelim(']') {137 var v1 Account138 if data := in.Raw(); in.Ok() {139 in.AddError((v1).UnmarshalJSON(data))140 }141 out.Accounts = append(out.Accounts, v1)142 in.WantComma()143 }144 in.Delim(']')145 }146 default:147 in.SkipRecursive()148 }149 in.WantComma()150 }151 in.Delim('}')152 if isTopLevel {153 in.Consumed()154 }155}156// UnmarshalJSON supports json.Unmarshaler interface157func (v *Accounts) UnmarshalJSON(data []byte) error {158 r := jlexer.Lexer{Data: data}159 decodeAccounts(&r, v)160 return r.Error()161}162func decodeAccount(in *jlexer.Lexer, out *Account) {163 var hasID bool164 isTopLevel := in.IsStart()165 if in.IsNull() {166 if isTopLevel {167 in.Consumed()168 }169 in.Skip()170 return171 }172 in.Delim('{')173 for !in.IsDelim('}') {174 key := in.UnsafeString()175 in.WantColon()176 if in.IsNull() {177 in.Skip()178 in.WantComma()179 continue180 }181 switch key {182 case "id":183 out.ID = uint32(in.Uint32())184 hasID = true185 case "email":186 out.Email = string(in.String())187 case "fname":188 out.FirstName = string(in.String())189 case "sname":190 out.SecondName = string(in.String())191 case "phone":192 out.Phone = string(in.String())193 case "sex":194 out.Sex = string(in.String())195 case "birth":196 if data := in.Raw(); in.Ok() {197 in.AddError((out.Birth).UnmarshalJSON(data))198 }199 case "country":200 out.Country = string(in.String())201 case "city":202 out.City = string(in.String())203 case "joined":204 if data := in.Raw(); in.Ok() {205 in.AddError((out.Joined).UnmarshalJSON(data))206 }207 case "status":208 out.Status = string(in.String())209 case "interests":210 if in.IsNull() {211 in.Skip()212 out.Interests = nil213 } else {214 in.Delim('[')215 if out.Interests == nil {216 if !in.IsDelim(']') {217 out.Interests = make([]string, 0, 4)218 } else {219 out.Interests = []string{}220 }221 } else {222 out.Interests = (out.Interests)[:0]223 }224 for !in.IsDelim(']') {225 var v4 string226 v4 = string(in.String())227 out.Interests = append(out.Interests, v4)228 in.WantComma()229 }230 in.Delim(']')231 }232 case "premium":233 if data := in.Raw(); in.Ok() {234 in.AddError((out.Premium).UnmarshalJSON(data))235 }236 case "likes":237 if in.IsNull() {238 in.Skip()239 out.Likes = nil240 } else {241 in.Delim('[')242 if out.Likes == nil {243 if !in.IsDelim(']') {244 out.Likes = make([]OneLike, 0, 2)245 } else {246 out.Likes = []OneLike{}247 }248 } else {249 out.Likes = (out.Likes)[:0]250 }251 for !in.IsDelim(']') {252 var v5 OneLike253 if data := in.Raw(); in.Ok() {254 in.AddError((v5).UnmarshalJSON(data))255 }256 out.Likes = append(out.Likes, v5)257 in.WantComma()258 }259 in.Delim(']')260 }261 default:262 in.AddError(errWrongFieldName)263 in.SkipRecursive()264 }265 in.WantComma()266 }267 in.Delim('}')268 if isTopLevel {269 in.Consumed()270 }271 if !hasID {272 in.AddError(ErrEmptyID)273 }274}275// UnmarshalJSON supports json.Unmarshaler interface276func (v *Account) UnmarshalJSON(data []byte) error {277 r := jlexer.Lexer{Data: data}278 decodeAccount(&r, v)279 return r.Error()280}281func decodeUpdateLikes(in *jlexer.Lexer, out *UpdateLikes) {282 isTopLevel := in.IsStart()283 if in.IsNull() {284 if isTopLevel {285 in.Consumed()286 }287 in.Skip()288 return289 }290 in.Delim('{')291 for !in.IsDelim('}') {292 key := in.UnsafeString()293 in.WantColon()294 if in.IsNull() {295 in.Skip()296 in.WantComma()297 continue298 }299 switch key {300 case "likes":301 if in.IsNull() {302 in.Skip()303 out.Likes = nil304 } else {305 in.Delim('[')306 if out.Likes == nil {307 if !in.IsDelim(']') {308 out.Likes = make([]OneUpdateLike, 0, 1)309 } else {310 out.Likes = []OneUpdateLike{}311 }312 } else {313 out.Likes = (out.Likes)[:0]314 }315 for !in.IsDelim(']') {316 var v1 OneUpdateLike317 if data := in.Raw(); in.Ok() {318 in.AddError((v1).UnmarshalJSON(data))319 }320 out.Likes = append(out.Likes, v1)321 in.WantComma()322 }323 in.Delim(']')324 }325 default:326 in.SkipRecursive()327 }328 in.WantComma()329 }330 in.Delim('}')331 if isTopLevel {332 in.Consumed()333 }334}335// UnmarshalJSON supports json.Unmarshaler interface336func (v *UpdateLikes) UnmarshalJSON(data []byte) error {337 r := jlexer.Lexer{Data: data}338 decodeUpdateLikes(&r, v)339 return r.Error()340}341func decodeOneUpdateLike(in *jlexer.Lexer, out *OneUpdateLike) {342 isTopLevel := in.IsStart()343 if in.IsNull() {344 if isTopLevel {345 in.Consumed()346 }347 in.Skip()348 return349 }350 in.Delim('{')351 for !in.IsDelim('}') {352 key := in.UnsafeString()353 in.WantColon()354 if in.IsNull() {355 in.Skip()356 in.WantComma()357 continue358 }359 switch key {360 case "likee":361 out.Likee = uint32(in.Uint32())362 case "liker":363 out.Liker = uint32(in.Uint32())364 case "ts":365 if data := in.Raw(); in.Ok() {366 in.AddError((out.Stamp).UnmarshalJSON(data))367 }368 default:369 in.SkipRecursive()370 }371 in.WantComma()372 }373 in.Delim('}')374 if isTopLevel {375 in.Consumed()376 }377}378// UnmarshalJSON supports json.Unmarshaler interface379func (v *OneUpdateLike) UnmarshalJSON(data []byte) error {380 r := jlexer.Lexer{Data: data}381 decodeOneUpdateLike(&r, v)382 return r.Error()383}...

Full Screen

Full Screen

options_test.go

Source:options_test.go Github

copy

Full Screen

...7 "github.com/stretchr/testify/require"8)9func TestSimpleOption(t *testing.T) {10 o := Options{}11 o.UnmarshalJSON([]byte(`{"key": "value"}`))12 args := o.ToArgs()13 assert.Equal(t, "--key=value", args[0])14}15func TestNoOptions(t *testing.T) {16 o := Options{}17 assert.Len(t, o.ToArgs(), 0)18}19func TestNestedOption(t *testing.T) {20 o := NewOptions(nil)21 o.UnmarshalJSON([]byte(`{"log-level": "debug", "memory": {"max-traces": 10000}}`))22 args := o.ToArgs()23 assert.Len(t, args, 2)24 sort.Strings(args)25 assert.Equal(t, "--log-level=debug", args[0])26 assert.Equal(t, "--memory.max-traces=10000", args[1])27}28func TestMarshalling(t *testing.T) {29 o := NewOptions(map[string]interface{}{30 "es.server-urls": "http://elasticsearch.default.svc:9200",31 "es.username": "elastic",32 "es.password": "changeme",33 })34 b, err := json.Marshal(o)35 assert.NoError(t, err)36 s := string(b)37 assert.Contains(t, s, `"es.password":"changeme"`)38 assert.Contains(t, s, `"es.server-urls":"http://elasticsearch.default.svc:9200"`)39 assert.Contains(t, s, `"es.username":"elastic"`)40}41func TestMarshallingWithFilter(t *testing.T) {42 o := NewOptions(map[string]interface{}{43 "es.server-urls": "http://elasticsearch.default.svc:9200",44 "memory.max-traces": "50000",45 })46 o = o.Filter("memory")47 args := o.ToArgs()48 assert.Len(t, args, 1)49 assert.Equal(t, "50000", o.Map()["memory.max-traces"])50}51func TestMultipleSubValues(t *testing.T) {52 o := NewOptions(nil)53 o.UnmarshalJSON([]byte(`{"es": {"server-urls": "http://elasticsearch:9200", "username": "elastic", "password": "changeme"}}`))54 args := o.ToArgs()55 assert.Len(t, args, 3)56}57func TestUnmarshalToArgs(t *testing.T) {58 tests := []struct {59 in string60 args []string61 err string62 }{63 {in: `^`, err: "invalid character '^' looking for beginning of value"},64 {65 in: `{"a": 5000000000, "b": 15.222, "c":true, "d": "foo"}`,66 args: []string{"--a=5000000000", "--b=15.222", "--c=true", "--d=foo"},67 },68 {69 in: `{"a": {"b": {"c": [{"d": "e", "f": {"g": {"h": "i"}}}]}}}`,70 err: "invalid option type, expect: string, got: map[string]interface {}",71 },72 }73 for _, test := range tests {74 opts := Options{}75 err := opts.UnmarshalJSON([]byte(test.in))76 if test.err != "" {77 assert.EqualError(t, err, test.err)78 } else {79 assert.NoError(t, err)80 args := opts.ToArgs()81 sort.SliceStable(args, func(i, j int) bool {82 return args[i] < args[j]83 })84 assert.Equal(t, test.args, args)85 }86 }87}88func TestMultipleSubValuesWithFilter(t *testing.T) {89 o := NewOptions(nil)90 o.UnmarshalJSON([]byte(`{"memory": {"max-traces": "50000"}, "es": {"server-urls": "http://elasticsearch:9200", "username": "elastic", "password": "changeme"}}`))91 o = o.Filter("memory")92 args := o.ToArgs()93 assert.Len(t, args, 1)94 assert.Equal(t, "50000", o.Map()["memory.max-traces"])95}96func TestMultipleSubValuesWithFilterWithArchive(t *testing.T) {97 o := NewOptions(nil)98 o.UnmarshalJSON([]byte(`{"memory": {"max-traces": "50000"}, "es": {"server-urls": "http://elasticsearch:9200", "username": "elastic", "password": "changeme"}, "es-archive": {"server-urls": "http://elasticsearch2:9200"}}`))99 o = o.Filter("es")100 args := o.ToArgs()101 assert.Len(t, args, 4)102 assert.Equal(t, "http://elasticsearch:9200", o.Map()["es.server-urls"])103 assert.Equal(t, "http://elasticsearch2:9200", o.Map()["es-archive.server-urls"])104 assert.Equal(t, "elastic", o.Map()["es.username"])105 assert.Equal(t, "changeme", o.Map()["es.password"])106}107func TestExposedMap(t *testing.T) {108 o := NewOptions(nil)109 o.UnmarshalJSON([]byte(`{"cassandra": {"servers": "cassandra:9042"}}`))110 assert.Equal(t, "cassandra:9042", o.Map()["cassandra.servers"])111}112func TestMarshallRaw(t *testing.T) {113 json := []byte(`{"cassandra": {"servers": "cassandra:9042"}}`)114 o := NewOptions(nil)115 o.json = &json116 bytes, err := o.MarshalJSON()117 assert.NoError(t, err)118 assert.Equal(t, bytes, json)119}120func TestMarshallEmpty(t *testing.T) {121 o := NewOptions(nil)122 json := []byte(`{}`)123 bytes, err := o.MarshalJSON()124 assert.NoError(t, err)125 assert.Equal(t, bytes, json)126}127func TestUpdate(t *testing.T) {128 // prepare129 o := NewOptions(map[string]interface{}{130 "key": "original",131 })132 // test133 o.Map()["key"] = "new"134 // verify135 assert.Equal(t, o.opts["key"], "new")136}137func TestStringMap(t *testing.T) {138 o := NewOptions(nil)139 err := o.UnmarshalJSON([]byte(`{"firstsarg":"v1", "additional-headers":["whatever:thing", "access-control-allow-origin:blerg"]}`))140 require.NoError(t, err)141 expected := map[string]string{"firstsarg": "v1"}142 strMap := o.StringMap()143 assert.Len(t, strMap, 1)144 assert.Equal(t, expected, strMap)145}146func TestDeepCopy(t *testing.T) {147 o1 := NewOptions(nil)148 err := o1.UnmarshalJSON([]byte(`{"firstsarg":"v1", "additional-headers":["whatever:thing", "access-control-allow-origin:blerg"]}`))149 require.NoError(t, err)150 copy := o1.opts.DeepCopy()151 assert.Equal(t, copy, &(o1.opts))152}153func TestRepetitiveArguments(t *testing.T) {154 o := NewOptions(nil)155 err := o.UnmarshalJSON([]byte(`{"firstsarg":"v1", "additional-headers":["whatever:thing", "access-control-allow-origin:blerg"]}`))156 require.NoError(t, err)157 expected := []string{"--additional-headers=access-control-allow-origin:blerg", "--additional-headers=whatever:thing", "--firstsarg=v1"}158 args := o.ToArgs()159 sort.SliceStable(args, func(i, j int) bool {160 return args[i] < args[j]161 })162 assert.Len(t, args, 3)163 assert.Equal(t, expected, args)164}...

Full Screen

Full Screen

UnmarshalJSON

Using AI Code Generation

copy

Full Screen

1{1 1 1}2{2 2 2}3{3 3 3}4{4 4 4}5func (v *v1) UnmarshalJSON(b []byte) error {6 aux := &struct {7 }{Alias: (*Alias)(v)}8 if err := json.Unmarshal(b, &aux); err != nil {9 }10}11func (v *v2) UnmarshalJSON(b []byte) error {12 aux := &struct {13 }{Alias: (*Alias)(v)}14 if err := json.Unmarshal(b, &aux); err != nil {15 }16}17func (v *v3) UnmarshalJSON(b []byte) error {18 aux := &struct {

Full Screen

Full Screen

UnmarshalJSON

Using AI Code Generation

copy

Full Screen

1err := json.Unmarshal(b, &v1)2if err != nil {3 log.Fatal(err)4}5err := json.Unmarshal(b, &v2)6if err != nil {7 log.Fatal(err)8}9err := json.Unmarshal(b, &v3)10if err != nil {11 log.Fatal(err)12}13err := json.Unmarshal(b, &v4)14if err != nil {15 log.Fatal(err)16}17err := json.Unmarshal(b, &v5)18if err != nil {19 log.Fatal(err)20}21err := json.Unmarshal(b, &v6)22if err != nil {23 log.Fatal(err)24}25err := json.Unmarshal(b, &v7)26if err != nil {27 log.Fatal(err)28}29err := json.Unmarshal(b, &v8)30if err != nil {31 log.Fatal(err)32}33err := json.Unmarshal(b, &v9)34if err != nil {35 log.Fatal(err)36}37err := json.Unmarshal(b, &v10)38if err != nil {39 log.Fatal(err)40}41err := json.Unmarshal(b, &v11)42if err != nil {43 log.Fatal(err)44}45err := json.Unmarshal(b, &v12)46if err != nil {47 log.Fatal(err)48}49err := json.Unmarshal(b, &v13)

Full Screen

Full Screen

UnmarshalJSON

Using AI Code Generation

copy

Full Screen

1func main() {2 err := json.Unmarshal([]byte(`{"foo": "bar"}`), &v1)3 if err != nil {4 panic(err)5 }6 fmt.Println(v1)7}8func main() {9 err := json.Unmarshal([]byte(`{"foo": "bar"}`), &v2)10 if err != nil {11 panic(err)12 }13 fmt.Println(v2)14}15{bar}16{bar}17func main() {18 err := json.Unmarshal([]byte(`{"foo": "bar"}`), &v2)19 if err != nil {20 panic(err)21 }22 fmt.Println(v2)23}24{bar}25func main() {

Full Screen

Full Screen

UnmarshalJSON

Using AI Code Generation

copy

Full Screen

1err := json.Unmarshal([]byte(str), &v1)2if err != nil {3 log.Fatal(err)4}5fmt.Println(v1)6err := json.Unmarshal([]byte(str), &v2)7if err != nil {8 log.Fatal(err)9}10fmt.Println(v2)11err := json.Unmarshal([]byte(str), &v3)12if err != nil {13 log.Fatal(err)14}15fmt.Println(v3)16err := json.Unmarshal([]byte(str), &v4)17if err != nil {18 log.Fatal(err)19}20fmt.Println(v4)21{10 20 30}22{10 20 30}23{10 20 30}24{10 20 30}

Full Screen

Full Screen

UnmarshalJSON

Using AI Code Generation

copy

Full Screen

1func main() {2 json.Unmarshal([]byte(`{"name":"John", "age": 30}`), &v1)3 fmt.Println(v1)4}5func main() {6 json.Unmarshal([]byte(`{"name":"John", "age": 30}`), &v2)7 fmt.Println(v2)8}9func main() {10 json.Unmarshal([]byte(`{"name":"John", "age": 30}`), &v3)11 fmt.Println(v3)12}13func main() {14 json.Unmarshal([]byte(`{"name":"John", "age": 30}`), &v4)15 fmt.Println(v4)16}17func main() {18 json.Unmarshal([]byte(`{"name":"John", "age": 30}`), &v5)19 fmt.Println(v5)20}21func main() {22 json.Unmarshal([]byte(`{"name":"John", "age": 30}`), &v6)23 fmt.Println(v6)24}25func main() {26 json.Unmarshal([]byte(`{"name":"John", "age": 30}`), &v7)27 fmt.Println(v7)28}29func main() {30 json.Unmarshal([]byte(`{"name":"John", "age": 30}`), &v8)31 fmt.Println(v8)32}33func main() {34 json.Unmarshal([]byte(`{"

Full Screen

Full Screen

UnmarshalJSON

Using AI Code Generation

copy

Full Screen

1func main() {2 if err := json.Unmarshal([]byte(`{"a":1,"b":2}`), &v1); err != nil {3 fmt.Println(err)4 }5 fmt.Printf("%v6}7func main() {8 if err := json.Unmarshal([]byte(`{"a":1,"b":2}`), &v2); err != nil {9 fmt.Println(err)10 }11 fmt.Printf("%v12}13func main() {14 if err := json.Unmarshal([]byte(`{"a":1,"b":2}`), &v3); err != nil {15 fmt.Println(err)16 }17 fmt.Printf("%v18}19func main() {20 if err := json.Unmarshal([]byte(`{"a":1,"b":2}`), &v4); err != nil {21 fmt.Println(err)22 }23 fmt.Printf("%v24}25func main() {26 if err := json.Unmarshal([]byte(`{"a":1,"b":2}`), &v5); err != nil {27 fmt.Println(err)28 }29 fmt.Printf("%v30}31func main() {32 if err := json.Unmarshal([]byte(`{"a":1,"b":2}`), &v6); err != nil {33 fmt.Println(err)34 }35 fmt.Printf("%v36}37func main() {38 if err := json.Unmarshal([]byte(`{"a":1,"b":2}`), &v7); err != nil {39 fmt.Println(err)40 }41 fmt.Printf("%v42}

Full Screen

Full Screen

UnmarshalJSON

Using AI Code Generation

copy

Full Screen

1func main() {2 err := json.Unmarshal([]byte(`{"Name":"foo","Age":10}`), &v)3 if err != nil {4 log.Fatalf("json.Unmarshal: %v", err)5 }6 fmt.Println(v)7}8{foo 10}9func main() {10 b, err := json.Marshal(v)11 if err != nil {12 log.Fatalf("json.Marshal: %v", err)13 }14 fmt.Println(string(b))15}16{"Name":"foo","Age":10}17func main() {18 var v interface{}19 v = v1{"foo", 10}20 b, err := json.Marshal(v)21 if err != nil {22 log.Fatalf("json.Marshal: %v", err)23 }24 fmt.Println(string(b))25}26{"Name":"foo","Age":10}27func main() {28 var v interface{}29 v = v1{"foo", 10}30 b, err := json.Marshal(v)31 if err != nil {32 log.Fatalf("json.Marshal: %v", err)33 }34 fmt.Println(string(b))35}

Full Screen

Full Screen

UnmarshalJSON

Using AI Code Generation

copy

Full Screen

1func main() {2 fmt.Println(v1)3 v1.UnmarshalJSON([]byte(`{"name":"john","age":20}`))4 fmt.Println(v1)5}6{0 john}7{20 john}8func (v *v1) UnmarshalJSON(data []byte) error {9 v2 := v2{}10 err := json.Unmarshal(data, &v2)11 if err != nil {12 }13}14func main() {15 fmt.Println(v1)16 v1.UnmarshalJSON([]byte(`{"name":"john","age":20}`))17 fmt.Println(v1)18}19{0 john}20{20 john}21func main() {22 fmt.Println(v1)23 err := json.Unmarshal([]byte(`{"name":"john","age":20}`), &v1)24 if err != nil {25 panic(err)26 }27 fmt.Println(v1)28}29{0 john}30{20 john}31func (v v1

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful