How to use Keytype method of html Package

Best K6 code snippet using html.Keytype

generator.go

Source:generator.go Github

copy

Full Screen

1package main2import (3 "bytes"4 "fmt"5 "html/template"6 "strings"7 "github.com/ditashi/jsbeautifier-go/jsbeautifier"8 "github.com/golang/protobuf/proto"9 "github.com/golang/protobuf/protoc-gen-go/descriptor"10 plugin "github.com/golang/protobuf/protoc-gen-go/plugin"11 "github.com/pseudomuto/protokit"12)13type twirp struct {14 params commandLineParams15 // Output buffer that holds the bytes we want to write out for a single file.16 // Gets reset after working on a file.17 output *bytes.Buffer18 // Map of all proto messages19 messages map[string]*message20 enums map[string]*protokit.EnumDescriptor21 // List of all APIs22 Apis []*api23 // List of all service Comments24 Comments *protokit.Comment25 // Service Name26 Name string27}28func newGenerator(params commandLineParams) *twirp {29 t := &twirp{30 params: params,31 messages: map[string]*message{},32 enums: map[string]*protokit.EnumDescriptor{},33 Apis: []*api{},34 output: bytes.NewBuffer(nil),35 }36 return t37}38func (t *twirp) Generate(in *plugin.CodeGeneratorRequest) *plugin.CodeGeneratorResponse {39 resp := new(plugin.CodeGeneratorResponse)40 t.scanAllMessages(in, resp)41 t.GenerateMarkdown(in, resp)42 return resp43}44// P forwards to g.gen.P, which prints output.45func (t *twirp) P(args ...string) {46 for _, v := range args {47 t.output.WriteString(v)48 }49 t.output.WriteByte('\n')50}51func (t *twirp) scanAllMessages(req *plugin.CodeGeneratorRequest, resp *plugin.CodeGeneratorResponse) {52 descriptors := protokit.ParseCodeGenRequest(req)53 for _, d := range descriptors {54 t.scanMessages(d)55 }56}57func (t *twirp) GenerateMarkdown(req *plugin.CodeGeneratorRequest, resp *plugin.CodeGeneratorResponse) {58 descriptors := protokit.ParseCodeGenRequest(req)59 for _, d := range descriptors {60 for _, sd := range d.GetServices() {61 t.scanService(sd)62 t.Name = *sd.Name63 for _, api := range t.Apis {64 api.Input = t.generateJsDocForMessage(api.Request)65 api.Output = t.generateJsDocForMessage(api.Reply)66 }67 t.generateDoc()68 name := strings.Replace(d.GetName(), ".proto", ".html", 1)69 resp.File = append(resp.File, &plugin.CodeGeneratorResponse_File{70 Name: proto.String(name),71 Content: proto.String(t.output.String()),72 })73 }74 }75}76func (t *twirp) scanMessages(d *protokit.FileDescriptor) {77 for _, ed := range d.GetEnums() {78 t.scanEnum(ed)79 }80 for _, md := range d.GetMessages() {81 t.scanMessage(md)82 }83}84func (t *twirp) scanEnum(md *protokit.EnumDescriptor) {85 t.enums["."+md.GetFullName()] = md86}87func (t *twirp) scanMessage(md *protokit.Descriptor) {88 for _, smd := range md.GetMessages() {89 t.scanMessage(smd)90 }91 for _, ed := range md.GetEnums() {92 t.scanEnum(ed)93 }94 {95 fields := make([]field, len(md.GetMessageFields()))96 maps := make(map[string]*descriptor.DescriptorProto)97 for _, t := range md.NestedType {98 if t.Options.GetMapEntry() {99 pkg := md.GetPackage()100 name := fmt.Sprintf(".%s.%s.%s", pkg, md.GetName(), t.GetName())101 maps[name] = t102 }103 }104 for i, fd := range md.GetMessageFields() {105 typeName := fd.GetTypeName()106 if typeName == "" {107 typeName = fd.GetType().String()108 }109 f := field{110 Name: fd.GetName(),111 Type: typeName,112 Doc: fd.GetComments().GetLeading(),113 Note: fd.GetComments().GetTrailing(),114 Label: fd.GetLabel(),115 }116 if e, ok := t.enums[fd.GetTypeName()]; ok {117 f.Type = "TYPE_ENUM"118 parts := []string{}119 for _, v := range e.GetValues() {120 line := fmt.Sprintf("%s(=%d) %s", v.GetName(), v.GetNumber(), v.GetComments().GetTrailing())121 parts = append(parts, line)122 }123 f.Doc = strings.Join(parts, "\n")124 }125 if m, ok := maps[f.Type]; ok {126 for _, ff := range m.GetField() {127 switch ff.GetName() {128 case "key":129 f.KeyType = ff.GetType().String()130 case "value":131 typeName := ff.GetTypeName()132 if typeName == "" {133 typeName = ff.GetType().String()134 }135 f.Type = typeName136 }137 }138 f.Label = 0139 }140 fields[i] = f141 }142 t.messages[md.GetFullName()] = &message{143 Name: md.GetName(),144 Doc: md.GetComments().GetTrailing(),145 Fields: fields,146 }147 }148}149type message struct {150 Name string151 Fields []field152 Label descriptor.FieldDescriptorProto_Label153 Doc string154}155type field struct {156 Name string157 Type string158 KeyType string159 Note string160 Doc string161 Label descriptor.FieldDescriptorProto_Label162}163func (f field) isRepeated() bool {164 return f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED165}166type api struct {167 Method string168 Path string169 Doc string170 Request *message171 Reply *message172 Input string173 Output string174}175func (t api) GetInputBeautifyCode() string {176 options := jsbeautifier.DefaultOptions()177 code, _ := jsbeautifier.Beautify(&t.Input, options)178 return code179}180func (t api) GetInputBeautifyCodes() []string {181 options := jsbeautifier.DefaultOptions()182 code, _ := jsbeautifier.Beautify(&t.Input, options)183 return strings.Split(code, "\n")184}185func (t api) GetOutputBeautifyCode() string {186 options := jsbeautifier.DefaultOptions()187 code, _ := jsbeautifier.Beautify(&t.Output, options)188 return code189}190func (t api) GetOutputBeautifyCodes() []string {191 options := jsbeautifier.DefaultOptions()192 code, _ := jsbeautifier.Beautify(&t.Output, options)193 return strings.Split(code, "\n")194}195func (t *twirp) scanService(d *protokit.ServiceDescriptor) {196 t.Comments = d.Comments197 for _, md := range d.GetMethods() {198 api := api{}199 api.Method = "POST"200 api.Path = t.params.pathPrefix + "/" + d.GetFullName() + "/" + md.GetName()201 doc := md.GetComments().GetLeading()202 // 支持文档换行203 api.Doc = strings.Replace(doc, "\n", "\n\n", -1)204 inputType := md.GetInputType()[1:] // trim leading dot205 api.Request = t.messages[inputType]206 outputType := md.GetOutputType()[1:] // trim leading dot207 api.Reply = t.messages[outputType]208 t.Apis = append(t.Apis, &api)209 }210}211func getType(t string) string {212 switch t {213 case "TYPE_STRING":214 return "string"215 case "TYPE_DOUBLE", "TYPE_FLOAT":216 return "float"217 case "TYPE_BOOL":218 return "bool"219 case "TYPE_INT64", "TYPE_UINT64", "TYPE_INT32", "TYPE_UINT32":220 return "int"221 default:222 return t223 }224}225func getTypeValue(t string) string {226 switch t {227 case "TYPE_STRING":228 return ""229 case "TYPE_DOUBLE", "TYPE_FLOAT":230 return "0.0"231 case "TYPE_BOOL":232 return "false"233 case "TYPE_INT64", "TYPE_UINT64", "TYPE_INT32", "TYPE_UINT32":234 return "0"235 default:236 return ""237 }238}239func (t *twirp) generateJsDocForField(field field) string {240 var js string241 var v, vt string242 disableDoc := false243 if field.Doc != "" {244 for _, line := range strings.Split(field.Doc, "\n") {245 js += "// " + line + "\n"246 }247 }248 if field.Type == "TYPE_STRING" {249 vt = "string"250 if field.isRepeated() {251 v = `["",""]`252 } else if field.KeyType != "" {253 v = fmt.Sprintf(`{"%s":""}`, getTypeValue(field.KeyType))254 vt = fmt.Sprintf("map<%s,string>", getType(field.KeyType))255 } else {256 v = `""`257 }258 } else if field.Type == "TYPE_DOUBLE" || field.Type == "TYPE_FLOAT" {259 vt = "float"260 if field.isRepeated() {261 v = "[0.0, 0.0]"262 } else if field.KeyType != "" {263 v = fmt.Sprintf(`{"%s":0.0}`, getTypeValue(field.KeyType))264 vt = fmt.Sprintf("map<%s,float>", getType(field.KeyType))265 } else {266 v = "0.0"267 }268 } else if field.Type == "TYPE_BOOL" {269 vt = "bool"270 if field.isRepeated() {271 v = "[false, false]"272 } else if field.KeyType != "" {273 v = fmt.Sprintf(`{"%s":false}`, getTypeValue(field.KeyType))274 vt = fmt.Sprintf("map<%s,bool>", getType(field.KeyType))275 } else {276 v = "false"277 }278 } else if field.Type == "TYPE_INT64" || field.Type == "TYPE_UINT64" {279 vt = "string(int64)"280 if field.isRepeated() {281 v = `["0", "0"]`282 } else if field.KeyType != "" {283 v = fmt.Sprintf(`{"%s":"0"}`, getTypeValue(field.KeyType))284 vt = fmt.Sprintf("map<%s,string(int64)>", getType(field.KeyType))285 } else {286 v = `"0"`287 }288 } else if field.Type == "TYPE_INT32" || field.Type == "TYPE_UINT32" {289 vt = "int"290 if field.isRepeated() {291 v = "[0, 0]"292 } else if field.KeyType != "" {293 v = fmt.Sprintf(`{"%s":0}`, getTypeValue(field.KeyType))294 vt = fmt.Sprintf("map<%s,int>", getType(field.KeyType))295 } else {296 v = "0"297 }298 } else if field.Type == "TYPE_ENUM" {299 vt = "string(enum)"300 if field.isRepeated() {301 v = `["", ""]`302 } else {303 v = `""`304 }305 } else if field.Type[0] == '.' {306 m := t.messages[field.Type[1:]]307 v = t.generateJsDocForMessage(m)308 if field.isRepeated() {309 doc := fmt.Sprintf("// type:<list<%s>>", m.Name)310 if field.Note != "" {311 doc = " " + field.Note312 }313 v = "[" + doc + "\n" + v + "]"314 } else if field.KeyType != "" {315 doc := fmt.Sprintf("// type:<map<%s,%s>>", getType(field.KeyType), m.Name)316 if field.Note != "" {317 doc = " " + field.Note318 }319 v = fmt.Sprintf("{%s\n\"%s\":%s}", doc, getTypeValue(field.KeyType), v)320 }321 disableDoc = true322 } else {323 v = "UNKNOWN"324 }325 if disableDoc {326 js += fmt.Sprintf("%s: %s,", field.Name, v)327 } else {328 js += fmt.Sprintf("\"%s\": %s, // type:<%s>", field.Name, v, vt)329 if field.Note != "" {330 js = js + ", " + field.Note331 }332 }333 js = strings.Trim(js, " ")334 js += "\n"335 return js336}337func (t *twirp) generateJsDocForMessage(m *message) string {338 var js string339 js += "{\n"340 for i, field := range m.Fields {341 tf := t.generateJsDocForField(field)342 if i == len(m.Fields)-1 {343 tf = strings.Replace(tf, ", //", " //", 1)344 }345 js += tf346 }347 js += "}"348 return js349}350func (t *twirp) generateDoc() {351 t.generateHTML()352 return353 options := jsbeautifier.DefaultOptions()354 t.P("# ", t.Name)355 t.P()356 comments := strings.Split(t.Comments.Leading, "\n")357 for _, value := range comments {358 t.P(value, " ")359 }360 t.P()361 for _, api := range t.Apis {362 anchor := strings.Replace(api.Path, "/", "", -1)363 anchor = strings.Replace(anchor, ".", "", -1)364 anchor = strings.ToLower(anchor)365 t.P(fmt.Sprintf("- [%s](#%s)", api.Path, anchor))366 }367 t.P()368 for _, api := range t.Apis {369 t.P("## ", api.Path)370 t.P()371 t.P(api.Doc)372 t.P()373 t.P("### Method")374 t.P()375 t.P(api.Method)376 t.P()377 t.P("### Request")378 t.P("```javascript")379 code, _ := jsbeautifier.Beautify(&api.Input, options)380 t.P(code)381 t.P("```")382 t.P()383 t.P("### Reply")384 t.P("```javascript")385 code, _ = jsbeautifier.Beautify(&api.Output, options)386 t.P(code)387 t.P("```")388 }389}390var temp = `391<head>392<link rel="stylesheet" href="./doc.css">393<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />394</head>395<script src="https://cdn.staticfile.org/jquery/3.5.0/jquery.js"></script>396<!-- 引入CodeMirror核心文件 -->397<script src="https://cdn.staticfile.org/codemirror/5.14.2/codemirror.min.js"></script>398<script src="https://cdn.staticfile.org/codemirror/5.14.2/mode/javascript/javascript.min.js"></script>399<script src="https://cdn.staticfile.org/codemirror/5.14.2/addon/fold/foldcode.min.js"></script>400<script src="https://cdn.staticfile.org/codemirror/5.14.2/addon/fold/foldgutter.min.js"></script>401<script src="https://cdn.staticfile.org/codemirror/5.14.2/addon/fold/brace-fold.min.js"></script>402<script src="https://cdn.staticfile.org/codemirror/5.14.2/addon/fold/indent-fold.min.js"></script>403<link rel="stylesheet" href="https://cdn.staticfile.org/codemirror/5.14.2/codemirror.min.css">404<link rel="stylesheet" href="https://cdn.staticfile.org/codemirror/5.14.2/theme/rubyblue.min.css">405<link rel="stylesheet" href="https://cdn.staticfile.org/codemirror/5.14.2/addon/fold/foldgutter.min.css">406<!-- bootstrap样式 -->407<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">408<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>409<script src="https://cdn.staticfile.org/datatables/1.10.20/js/jquery.dataTables.min.js"></script>410<link rel="stylesheet" href="./doc.css">411<h1 id='{{.Name}}'>{{.Name}}</h1>412<p>{{.Comments.Leading}}</p>413<ul>414 {{range .Apis}}415 <li><a href='#{{.Path}}'>{{.Path}}</a></li>416 {{end}}417</ul>418{{range $index, $v := .Apis}}419 <h2 id="{{.Path}}">{{.Path}}</h2>420 <h3 id="method">Method</h3>421 <p>POST</p>422 <div class="row-fluid">423 <h3 id="request" style="display:inline-block;">Request</h3><button class="sp-curl" onclick="sendReq(this)" req="reqArea{{$index}}" path={{.Path}} resp="respArea{{$index}}" aIndex={{$index}} >CURL</button>424 </div>425 <code id="reqCode{{$index}}" aIndex={{$index}} isReq=true>{{.GetInputBeautifyCode}}</code>426 <h3 id="reply">Reply</h3>427 <code id="respCode{{$index}}" aIndex={{$index}}>{{.GetOutputBeautifyCode}}</code>428{{end}}429<script>430 var isInitMirrorCode = {}431 var cmMap = {}432 $('code').click(function(){433 var isReq = $(this).attr("isReq"); 434 console.log(isReq)435 var i = $(this).attr("aIndex");436 var ele = this;437 var str = $(ele).text();438 areaID = ""439 if (isReq) {440 areaID = "reqArea" + i441 } else {442 areaID = "respArea" + i443 }444 if (isInitMirrorCode.hasOwnProperty(areaID)) {445 return446 }447 $(ele).hide();448 $(ele).after("<textarea id="+areaID+">"+str+"</textarea>");449 450 var editor = CodeMirror.fromTextArea(document.getElementById(areaID), {451 theme: 'rubyblue',452 mode: "javascript",453 lineNumbers: true,454 viewportMargin:Infinity,455 foldGutter: true,456 readOnly:false,457 gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]458 });459 460 isInitMirrorCode[areaID] = true 461 if (isReq) {462 editor.on('change', e => {463 document.getElementById("reqArea"+ i).textContent = e.getValue();464 });465 } else {466 cmMap[i] = editor;467 }468 });469 470 var data;471 window.onload = function init() {472 console.log("init")473 data = {{.}}474 }475 function sendReq(obj) {476 index = obj.getAttribute("aIndex")477 document.getElementById("reqCode"+index).click();478 document.getElementById("respCode"+index).click();479 reqArea = document.getElementById(obj.getAttribute("req"));480 reqBody = JSON.parse(reqArea.textContent.split("\n").map(x => x.replace(/\/\/.*/g, "")).join(""))481 resp = $.ajax({482 type: "POST", 483 url:"http://127.0.0.1:8080/twirp"+obj.getAttribute("path"),484 data: JSON.stringify(reqBody),485 contentType: 'application/json',486 dataType: "json",487 success: function (data, status) {488 console.log(data, status, obj)489 respArea = document.getElementById(obj.getAttribute("resp"));490 // if (!cmMap.hasOwnProperty(index)) {491 // var respCM = CodeMirror.fromTextArea(respArea, {492 // theme: 'rubyblue',493 // mode: "javascript",494 // lineNumbers: true,495 // viewportMargin:Infinity,496 // foldGutter: true,497 // autoRefresh: true,498 // readOnly:false,499 // gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]500 // });501 // cmMap[index] = respCM502 // }503 504 console.log(index)505 console.log(JSON.stringify(data, undefined, 4))506 console.log(cmMap)507 cmMap[index].setValue(JSON.stringify(data, undefined, 4))508 cmMap[index].refresh509 }510 })511 }512</script>513`514func (t *twirp) generateHTML() {515 ht, err := template.New("doc").Parse(temp)516 if err != nil {517 return518 }519 //ht.Execute(t.output, t)520 err = ht.ExecuteTemplate(t.output, "doc", t)521 if err != nil {522 panic(err)523 }524}...

Full Screen

Full Screen

model_appliance_all_of_ntp_servers.go

Source:model_appliance_all_of_ntp_servers.go Github

copy

Full Screen

1/*2 * AppGate SDP Controller REST API3 *4 * # About This specification documents the REST API calls for the AppGate SDP Controller. Please refer to the Integration chapter in the manual or contact AppGate support with any questions about this functionality. # Getting Started Requirements for API scripting: - Access to the peer interface (default port 444) of a Controller appliance. (https://sdphelp.appgate.com/adminguide/appliances-configure.html?anchor=peer) - An API user with relevant permissions. (https://sdphelp.appgate.com/adminguide/administrative-roles-configure.html) - In order to use the simple login API, Admin MFA must be disabled or the API user must be excluded. (https://sdphelp.appgate.com/adminguide/mfa-for-admins.html) # Base path HTTPS requests must be sent to the Peer Interface hostname and port, with **_/admin** path. For example: **https://appgate.company.com:444/admin** All requests must have the **Accept** header as: **application/vnd.appgate.peer-v12+json** # API Conventions API conventions are important to understand and follow strictly. - While updating objects (via PUT), entire object must be sent with all fields. - For example, if in order to add a remedy method to the condition below: ``` { \"id\": \"12699e27-b584-464a-81ee-5b4784b6d425\", \"name\": \"Test\", \"notes\": \"Making a point\", \"tags\": [\"test\", \"tag\"], \"expression\": \"return true;\", \"remedyMethods\": [] } ``` - send the entire object with updated and non-updated fields: ``` { \"id\": \"12699e27-b584-464a-81ee-5b4784b6d425\", \"name\": \"Test\", \"notes\": \"Making a point\", \"tags\": [\"test\", \"tag\"], \"expression\": \"return true;\", \"remedyMethods\": [{\"type\": \"DisplayMessage\", \"message\": \"test message\"}] } ``` - In case Controller returns an error (non-2xx HTTP status code), response body is JSON. The \"message\" field contains information abot the error. HTTP 422 \"Unprocessable Entity\" has extra `errors` field to list all the issues with specific fields. - Empty string (\"\") is considered a different value than \"null\" or field being omitted from JSON. Omitting the field is recommend if no value is intended. Empty string (\"\") will be almost always rejected as invalid value. - There are common pattern between many objects: - **Configuration Objects**: There are many objects with common fields, namely \"id\", \"name\", \"notes\", \"created\" and \"updated\". These entities are listed, queried, created, updated and deleted in a similar fashion. - **Distinguished Name**: Users and Devices are identified with what is called Distinguished Names, as used in LDAP. The distinguished format that identifies a device and a user combination is \"CN=\\<Device ID\\>,CN=\\<username\\>,OU=\\<Identity Provider Name\\>\". Some objects have the \"userDistinguishedName\" field, which does not include the CN for Device ID. This identifies a user on every device.5 *6 * API version: API version 127 * Contact: appgatesdp.support@appgate.com8 * Generated by: OpenAPI Generator (https://openapi-generator.tech)9 */10package openapi11import (12 "encoding/json"13)14// ApplianceAllOfNtpServers NTP server.15type ApplianceAllOfNtpServers struct {16 // Hostname or IP of the NTP server.17 Hostname string `json:"hostname"`18 // Type of key to use for secure NTP communication.19 KeyType *string `json:"keyType,omitempty"`20 // Key to use for secure NTP communication.21 Key *string `json:"key,omitempty"`22}23// NewApplianceAllOfNtpServers instantiates a new ApplianceAllOfNtpServers object24// This constructor will assign default values to properties that have it defined,25// and makes sure properties required by API are set, but the set of arguments26// will change when the set of required properties is changed27func NewApplianceAllOfNtpServers(hostname string) *ApplianceAllOfNtpServers {28 this := ApplianceAllOfNtpServers{}29 this.Hostname = hostname30 return &this31}32// NewApplianceAllOfNtpServersWithDefaults instantiates a new ApplianceAllOfNtpServers object33// This constructor will only assign default values to properties that have it defined,34// but it doesn't guarantee that properties required by API are set35func NewApplianceAllOfNtpServersWithDefaults() *ApplianceAllOfNtpServers {36 this := ApplianceAllOfNtpServers{}37 return &this38}39// GetHostname returns the Hostname field value40func (o *ApplianceAllOfNtpServers) GetHostname() string {41 if o == nil {42 var ret string43 return ret44 }45 return o.Hostname46}47// GetHostnameOk returns a tuple with the Hostname field value48// and a boolean to check if the value has been set.49func (o *ApplianceAllOfNtpServers) GetHostnameOk() (*string, bool) {50 if o == nil {51 return nil, false52 }53 return &o.Hostname, true54}55// SetHostname sets field value56func (o *ApplianceAllOfNtpServers) SetHostname(v string) {57 o.Hostname = v58}59// GetKeyType returns the KeyType field value if set, zero value otherwise.60func (o *ApplianceAllOfNtpServers) GetKeyType() string {61 if o == nil || o.KeyType == nil {62 var ret string63 return ret64 }65 return *o.KeyType66}67// GetKeyTypeOk returns a tuple with the KeyType field value if set, nil otherwise68// and a boolean to check if the value has been set.69func (o *ApplianceAllOfNtpServers) GetKeyTypeOk() (*string, bool) {70 if o == nil || o.KeyType == nil {71 return nil, false72 }73 return o.KeyType, true74}75// HasKeyType returns a boolean if a field has been set.76func (o *ApplianceAllOfNtpServers) HasKeyType() bool {77 if o != nil && o.KeyType != nil {78 return true79 }80 return false81}82// SetKeyType gets a reference to the given string and assigns it to the KeyType field.83func (o *ApplianceAllOfNtpServers) SetKeyType(v string) {84 o.KeyType = &v85}86// GetKey returns the Key field value if set, zero value otherwise.87func (o *ApplianceAllOfNtpServers) GetKey() string {88 if o == nil || o.Key == nil {89 var ret string90 return ret91 }92 return *o.Key93}94// GetKeyOk returns a tuple with the Key field value if set, nil otherwise95// and a boolean to check if the value has been set.96func (o *ApplianceAllOfNtpServers) GetKeyOk() (*string, bool) {97 if o == nil || o.Key == nil {98 return nil, false99 }100 return o.Key, true101}102// HasKey returns a boolean if a field has been set.103func (o *ApplianceAllOfNtpServers) HasKey() bool {104 if o != nil && o.Key != nil {105 return true106 }107 return false108}109// SetKey gets a reference to the given string and assigns it to the Key field.110func (o *ApplianceAllOfNtpServers) SetKey(v string) {111 o.Key = &v112}113func (o ApplianceAllOfNtpServers) MarshalJSON() ([]byte, error) {114 toSerialize := map[string]interface{}{}115 if true {116 toSerialize["hostname"] = o.Hostname117 }118 if o.KeyType != nil {119 toSerialize["keyType"] = o.KeyType120 }121 if o.Key != nil {122 toSerialize["key"] = o.Key123 }124 return json.Marshal(toSerialize)125}126type NullableApplianceAllOfNtpServers struct {127 value *ApplianceAllOfNtpServers128 isSet bool129}130func (v NullableApplianceAllOfNtpServers) Get() *ApplianceAllOfNtpServers {131 return v.value132}133func (v *NullableApplianceAllOfNtpServers) Set(val *ApplianceAllOfNtpServers) {134 v.value = val135 v.isSet = true136}137func (v NullableApplianceAllOfNtpServers) IsSet() bool {138 return v.isSet139}140func (v *NullableApplianceAllOfNtpServers) Unset() {141 v.value = nil142 v.isSet = false143}144func NewNullableApplianceAllOfNtpServers(val *ApplianceAllOfNtpServers) *NullableApplianceAllOfNtpServers {145 return &NullableApplianceAllOfNtpServers{value: val, isSet: true}146}147func (v NullableApplianceAllOfNtpServers) MarshalJSON() ([]byte, error) {148 return json.Marshal(v.value)149}150func (v *NullableApplianceAllOfNtpServers) UnmarshalJSON(src []byte) error {151 v.isSet = true152 return json.Unmarshal(src, &v.value)153}...

Full Screen

Full Screen

tbody_keys_test.go

Source:tbody_keys_test.go Github

copy

Full Screen

1package utils2import (3 "nod32-update-mirror/pkg/keys"4 "testing"5 "github.com/stretchr/testify/assert"6)7func TestSimpleTBodyKeysExtract(t *testing.T) {8 html := `9<table class="table_eav">10 <thead>11 <tr><th colspan="3">12 <h3>ESET NOD32 Antivirus (EAV) 4-8</h3>13 </th></tr>14 </thead>15 <tbody id="block_keys1" class="keys_eav">16 <tr class="bgkeyhead">17 <td>Имя пользователя</td>18 <td>Пароль</td>19 <td>Истекает</td>20 </tr>21 <tr>22 <td id="first_name_eav" class="name" data-tooltip="Нажмите, чтобы скопировать"23data-clipboard-text="EAV-0263094078">EAV-0263094078</td>24 <td id="first_pass_eav" class="password" data-tooltip="Нажмите, чтобы скопировать"25data-clipboard-text="477r6sf2rc">477r6sf2rc</td>26 <td class="dexpired">07.01.2020</td>27 </tr>28 <tr>29 <td id="twice_name_eav" class="name" data-tooltip="Нажмите, чтобы скопировать"30data-clipboard-text="TRIAL-0263727323">TRIAL-0263727323</td>31 <td id="twice_pass_eav" class="password" data-tooltip="Нажмите, чтобы скопировать"32data-clipboard-text="s76xh9bm5s">s76xh9bm5s</td>33 <td class="dexpired">24.10.2019</td>34 </tr>35 </tbody>36</table>37<table class="table_eis double">38 <thead>39 <tr><th colspan="3">40 <h3>ESET Smart Security (ESS) 9-12</h3>41 </th></tr>42 </thead>43 <tbody id="block_keys5" class="keys_eis">44 <tr class="bgkeyhead">45 <td colspan="2">Лицензионный ключ</td>46 <td>Истекает</td>47 </tr>48 <tr>49 <td id="first_big_smart910" class="password" colspan="2" data-tooltip="Нажмите, чтобы скопировать"50data-clipboard-text="CC66-XA55-MBCM-N9NE-PAA8">CC66-XA55-MBCM-N9NE-PAA8</td>51 <td class="dexpired">15.12.2019</td>52 </tr>53 <tr>54 <td id="twice_big_smart910" class="password" colspan="2" data-tooltip="Нажмите, чтобы скопировать"55data-clipboard-text="VND8-W333-794S-SNCR-M3AD">VND8-W333-794S-SNCR-M3AD</td>56 <td class="dexpired">10.04.2020</td>57 </tr>58 </tbody>59</table>60<table class="table_essp"><thead><tr><th>61 <h3>ESET Smart Security Premium 10-12</h3>62 </th></tr></thead><tbody id="block_keys4" class="keys_essp">63<tr><td id="firstPremium10" class="password" colspan="2">9VJ9-X9XR-UBDH-4AC6-GXHD</td>64</tr><tr><td id="twicePremium10" class="password" colspan="2">578B-X7WD-X9PA-C54S-CNTN</td>65</tr></tbody></table>66`67 result1, err := SimpleTBodyKeysExtract(html, "block_keys1", []keys.KeyType{keys.KeyTypeEAVv4, keys.KeyTypeEAVv5})68 assert.NoError(t, err)69 assert.Len(t, *result1, 2)70 assert.Contains(t, *result1, keys.Key{71 ID: "EAV-0263094078",72 Password: "477r6sf2rc",73 Types: []keys.KeyType{keys.KeyTypeEAVv4, keys.KeyTypeEAVv5},74 ExpiringAtUnix: 1578355200,75 })76 assert.Contains(t, *result1, keys.Key{77 ID: "TRIAL-0263727323",78 Password: "s76xh9bm5s",79 Types: []keys.KeyType{keys.KeyTypeEAVv4, keys.KeyTypeEAVv5},80 ExpiringAtUnix: 1571875200,81 })82 result2, err := SimpleTBodyKeysExtract(html, "block_keys5", []keys.KeyType{keys.KeyTypeESSv9})83 assert.NoError(t, err)84 assert.Len(t, *result2, 2)85 assert.Contains(t, *result2, keys.Key{86 ID: "CC66-XA55-MBCM-N9NE-PAA8",87 Password: "",88 Types: []keys.KeyType{keys.KeyTypeESSv9},89 ExpiringAtUnix: 1576368000,90 })91 assert.Contains(t, *result2, keys.Key{92 ID: "VND8-W333-794S-SNCR-M3AD",93 Password: "",94 Types: []keys.KeyType{keys.KeyTypeESSv9},95 ExpiringAtUnix: 1586476800,96 })97 result3, err := SimpleTBodyKeysExtract(html, "block_keys4", []keys.KeyType{keys.KeyTypeESSPv10})98 assert.NoError(t, err)99 assert.Len(t, *result3, 2)100 assert.Contains(t, *result3, keys.Key{101 ID: "9VJ9-X9XR-UBDH-4AC6-GXHD",102 Password: "",103 Types: []keys.KeyType{keys.KeyTypeESSPv10},104 ExpiringAtUnix: 0,105 })106 assert.Contains(t, *result3, keys.Key{107 ID: "578B-X7WD-X9PA-C54S-CNTN",108 Password: "",109 Types: []keys.KeyType{keys.KeyTypeESSPv10},110 ExpiringAtUnix: 0,111 })112}...

Full Screen

Full Screen

Keytype

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 doc, _ := html.Parse(strings.NewReader("<html><head><title>Test</title></head><body><h1>Hello!</h1></body></html>"))4 fmt.Println(doc.FirstChild.Data)5 fmt.Println(doc.FirstChild.NextSibling.Data)6 fmt.Println(doc.FirstChild.NextSibling.FirstChild.Data)7}8import (9func main() {10 doc, _ := html.Parse(strings.NewReader("<html><head><title>Test</title></head><body><h1>Hello!</h1></body></html>"))11 fmt.Println(doc.FirstChild.Type)12 fmt.Println(doc.FirstChild.NextSibling.Type)13 fmt.Println(doc.FirstChild.NextSibling.FirstChild.Type)14}15import (16func main() {17 doc, _ := html.Parse(strings.NewReader("<html><head><title>Test</title></head><body><h1>Hello!</h1></body></html>"))18 fmt.Println(doc.FirstChild.DataAtom)19 fmt.Println(doc.FirstChild.NextSibling.DataAtom)20 fmt.Println(doc.FirstChild.NextSibling.FirstChild.DataAtom)21}22import (23func main() {24 doc, _ := html.Parse(strings.NewReader("<html><head><title>Test</title></head><body><h1>Hello!</h1></body></html>"))25 fmt.Println(doc.FirstChild.Attr)26 fmt.Println(doc.FirstChild.NextSibling.Attr)27 fmt.Println(doc.FirstChild.NextSibling.FirstChild.Attr)28}29import (30func main() {31 doc, _ := html.Parse(strings.NewReader("<html><head><title>Test</title></head><body><h1>Hello!</h1></body

Full Screen

Full Screen

Keytype

Using AI Code Generation

copy

Full Screen

1import (2func init() {3 tpl = template.Must(template.ParseGlob("templates/*"))4}5func main() {6 http.HandleFunc("/", index)7 http.HandleFunc("/about", about)8 http.ListenAndServe(":8080", csrf.Protect([]byte("32-byte-long-auth-key"))(http.DefaultServeMux))9}10func index(w http.ResponseWriter, r *http.Request) {11 tpl.ExecuteTemplate(w, "index.gohtml", csrf.TemplateField(r))12}13func about(w http.ResponseWriter, r *http.Request) {14 fmt.Println("about page")15}16import (17func init() {18 tpl = template.Must(template.ParseGlob("templates/*"))19}20func main() {21 http.HandleFunc("/", index)22 http.HandleFunc("/about", about)23 http.ListenAndServe(":8080", csrf.Protect([]byte("32-byte-long-auth-key"))(http.DefaultServeMux))24}25func index(w http.ResponseWriter, r *http.Request) {26 tpl.ExecuteTemplate(w, "index.gohtml", csrf.TemplateField(r))27}28func about(w http.ResponseWriter, r *http.Request) {29 fmt.Println("about page")30}31import (32func init() {33 tpl = template.Must(template.ParseGlob("templates/*"))34}35func main() {36 http.HandleFunc("/", index)37 http.HandleFunc("/about", about)38 http.ListenAndServe(":8080", csrf.Protect([]byte("32-byte-long-auth-key"))(http.DefaultServeMux))39}40func index(w http.ResponseWriter, r *http.Request) {41 tpl.ExecuteTemplate(w, "index.gohtml", csrf.TemplateField(r))42}43func about(w http.ResponseWriter, r *http.Request) {44 fmt.Println("about page")45}46import (

Full Screen

Full Screen

Keytype

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(html.EscapeString("<script>alert('hello')</script>"))4}5import (6func main() {7 t, _ := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)8 t.ExecuteTemplate(os.Stdout, "T", template.HTML("<script>alert('you have been pwned')</script>"))9}10import (11func main() {12 t, _ := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)13 t.ExecuteTemplate(os.Stdout, "T", template.JS("<script>alert('you have been pwned')</script>"))14}15import (16func main() {17 t, _ := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)18}19import (20func main() {21 t, _ := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)22 t.ExecuteTemplate(os.Stdout, "T", template.CSS("body {background-color:#ffff00}"))23}

Full Screen

Full Screen

Keytype

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(html.EscapeString("<script>alert(\"Hello, world!\")</script>"))4}5import (6func main() {7 tmpl, _ := template.New("foo").Parse("{{.}}")8 tmpl.Execute(os.Stdout, "<script>alert(\"Hello, world!\")</script>")9}10import (11func main() {12 tmpl, _ := template.New("foo").Parse("{{.}}")13 tmpl.Execute(os.Stdout, "<script>alert(\"Hello, world!\")</script>")14}15import (16func main() {17 tmpl, _ := template.New("foo").Parse("{{.}}")18 tmpl.Execute(os.Stdout, "<script>alert(\"Hello, world!\")</script>")19}20import (21func main() {22 tmpl, _ := template.New("foo").Parse("{{.}}")23 tmpl.Execute(os.Stdout, "<script>alert(\"Hello, world!\")</script>")24}25import (26func main() {27 tmpl, _ := template.New("foo").Parse("{{.}}")28 tmpl.Execute(os.Stdout, "<script>alert(\"Hello, world!\")</script>")29}30import (31func main() {32 tmpl, _ := template.New("foo").Parse("{{.}}")33 tmpl.Execute(os.Stdout, "<script>alert(\"Hello, world!\")</script>")34}35import (36func main() {

Full Screen

Full Screen

Keytype

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(stringutil.Reverse("!oG ,olleH"))4 fmt.Println(stringutil.MyName)5}6import (7func main() {8 fmt.Println(icomefromalaska.ReverseK("!oG ,olleH"))9 fmt.Println(icomefromalaska.YourName)10}11import (12func main() {13 fmt.Println(stringutil.Reverse("!oG ,olleH"))14 fmt.Println(stringutil.MyName)15 fmt.Println(icomefromalaska.ReverseK("!oG ,olleH"))16 fmt.Println(icomefromalaska.YourName)17}18import (19func main() {20 fmt.Println(stringutil.Reverse("!oG ,olleH"))21 fmt.Println(stringutil.MyName)22 fmt.Println(icomefromalaska.ReverseK("!oG ,olleH"))23 fmt.Println(icomefromalaska.YourName)24 fmt.Println("Hello")25}26import (27func main() {28 fmt.Println(stringutil.Reverse("!oG ,olleH"))29 fmt.Println(stringutil.MyName)30 fmt.Println(icomefromalaska.ReverseK("!oG ,olleH"))31 fmt.Println(icomefromalaska.YourName)32 fmt.Println("Hello")33 fmt.Println("Hello")34}35import (

Full Screen

Full Screen

Keytype

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(html.KeygenType())4}5import (6func main() {7 fmt.Println(html.KeygenType())8}9import (10func main() {11 fmt.Println(html.KeygenType())12}13import (14func main() {15 fmt.Println(html.KeygenType())16}17import (18func main() {19 fmt.Println(html.KeygenType())20}21import (22func main() {23 fmt.Println(html.KeygenType())24}25import (26func main() {27 fmt.Println(html.KeygenType())28}29import (30func main() {31 fmt.Println(html.KeygenType())32}33import (34func main() {35 fmt.Println(html.KeygenType())36}

Full Screen

Full Screen

Keytype

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(html.EscapeString("This is a test"))4 fmt.Println(strings.Replace("This is a test", "a", "b", -1))5}6import (7func main() {8 fmt.Println(html.UnescapeString("This is a test"))9}10import (11func main() {12 t := template.Must(template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`))13 err := t.ExecuteTemplate(os.Stdout, "T", template.HTML("<script>alert('you have been pwned')</script>"))14 if err != nil {15 log.Fatal(err)16 }17}18Hello, <script>alert('you have been pwned')</script>!19import (20func main() {21 t := template.Must(template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`))22 if err != nil {23 log.Fatal(err)24 }25}26import (27func main() {28 t := template.Must(template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`))29 err := t.ExecuteTemplate(os.Stdout, "T", template.JS("alert('you have been pwned')"))30 if err != nil {31 log.Fatal(err)32 }33}34Hello, alert('you have been pwned')!35import (

Full Screen

Full Screen

Keytype

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "html"3func main() {4 html1 = html.Keytype("H")5 fmt.Println(html1)6}7GoLang HTML Keytype() Method

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.

Run K6 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful