Skip to content

Commit

Permalink
add testclient, fix log, fix dds
Browse files Browse the repository at this point in the history
  • Loading branch information
sjmshsh committed Aug 16, 2023
1 parent 95bdc60 commit 93bae5f
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 0 deletions.
101 changes: 101 additions & 0 deletions tools/deepcopy-gen/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
"bytes"
"flag"
"fmt"
"go/format"
"log"
"os"
"text/template"

"gopkg.in/yaml.v2"
)

type ConfigData struct {
ProtoResource string
}

type Resource struct {
OutPut string `yaml:"out-put"`
Name []string `yaml:"name"`
}

func readYAMLFile(filePath string) (*Resource, error) {
yamlFile, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}

var config Resource

err = yaml.Unmarshal(yamlFile, &config)
if err != nil {
return nil, err
}

return &config, nil
}

func main() {
config, err := readYAMLFile("tools/deepcopy-gen/metadata.yaml")
if err != nil {
panic(err)
}
outputFile := config.OutPut
names := config.Name
flag.Parse()

tmpl := template.Must(template.ParseFiles("tools/deepcopy-gen/template.go.tmpl"))

var typeList []ConfigData

for _, name := range names {
data := ConfigData{
ProtoResource: name,
}
typeList = append(typeList, data)
}

var buffer bytes.Buffer
if err := tmpl.Execute(&buffer, typeList); err != nil {
log.Fatal(err)
}

out, err := format.Source(buffer.Bytes())
if err != nil {
log.Fatal(err)
}
// Output
if outputFile == "" {
fmt.Println(string(out))
} else {
file, err := os.Create(outputFile)
if err != nil {
panic(err)
}
defer file.Close()

_, err = file.Write(out)
if err != nil {
panic(err)
}
}
}
19 changes: 19 additions & 0 deletions tools/deepcopy-gen/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

out-put: api/resource/v1alpha1/toClient_deepcopy.go
name:
- AuthorizationPolicySource
- AuthorizationPolicyCondition
55 changes: 55 additions & 0 deletions tools/deepcopy-gen/template.go.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Code generated by tools/generate_deepcopy_types.go. DO NOT EDIT!

package dubbo_apache_org_v1alpha1

import (
fmt "fmt"
proto "github.com/gogo/protobuf/proto"
_ "github.com/gogo/protobuf/types"
math "math"
)

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf

{{range $index, $element := .}}
// DeepCopyInto supports using {{ .ProtoResource }} within kubernetes types, where deepcopy-gen is used.
func (in *{{ .ProtoResource }}) DeepCopyInto(out *{{ .ProtoResource }}) {
p := proto.Clone(in).(*{{ .ProtoResource }})
*out = *p
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new {{ .ProtoResource }}.
func (in *{{ .ProtoResource }}) DeepCopy() *{{ .ProtoResource }} {
if in == nil {
return nil
}
out := new({{ .ProtoResource }})
in.DeepCopyInto(out)
return out
}

// DeepCopyInterface is an autogenerated deepcopy function, copying the receiver, creating a new {{ .ProtoResource }}.
func (in *{{ .ProtoResource }}) DeepCopyInterface() interface{} {
return in.DeepCopy()
}
{{end}}

0 comments on commit 93bae5f

Please sign in to comment.