Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
15f32e0e30 | |||
066b9f7ad2 | |||
42bb490180 | |||
c1f7ce2b85 | |||
87bda92fac | |||
ba04b02cf8 |
@ -58,7 +58,6 @@ func (i *consumer) Priority() int {
|
||||
return event.PRIORITY - 1
|
||||
}
|
||||
|
||||
func (i *consumer) Close(ctx context.Context) error {
|
||||
func (i *consumer) Close(ctx context.Context) {
|
||||
i.ctx.Done()
|
||||
return nil
|
||||
}
|
||||
|
@ -1 +1,7 @@
|
||||
package apps
|
||||
|
||||
import (
|
||||
_ "122.51.31.227/go-course/go18/devcloud/cmdb/apps/resource/impl"
|
||||
_ "122.51.31.227/go-course/go18/devcloud/cmdb/apps/secret/impl"
|
||||
_ "122.51.31.227/go-course/go18/devcloud/cmdb/apps/secret/sync"
|
||||
)
|
||||
|
@ -32,7 +32,3 @@ const (
|
||||
)
|
||||
|
||||
type TYPE string
|
||||
|
||||
const ()
|
||||
|
||||
type STATUS string
|
||||
|
@ -1 +1,31 @@
|
||||
package impl
|
||||
|
||||
import (
|
||||
"122.51.31.227/go-course/go18/devcloud/cmdb/apps/resource"
|
||||
"github.com/infraboard/mcube/v2/ioc"
|
||||
"github.com/infraboard/mcube/v2/ioc/config/datasource"
|
||||
)
|
||||
|
||||
func init() {
|
||||
ioc.Controller().Registry(&ResourceServiceImpl{})
|
||||
}
|
||||
|
||||
var _ resource.Service = (*ResourceServiceImpl)(nil)
|
||||
|
||||
type ResourceServiceImpl struct {
|
||||
ioc.ObjectImpl
|
||||
}
|
||||
|
||||
func (s *ResourceServiceImpl) Name() string {
|
||||
return resource.APP_NAME
|
||||
}
|
||||
|
||||
func (s *ResourceServiceImpl) Init() error {
|
||||
if datasource.Get().AutoMigrate {
|
||||
err := datasource.DB().AutoMigrate(&resource.Resource{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -1 +1,28 @@
|
||||
package impl
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"122.51.31.227/go-course/go18/devcloud/cmdb/apps/resource"
|
||||
"github.com/infraboard/mcube/v2/ioc/config/datasource"
|
||||
"github.com/infraboard/mcube/v2/types"
|
||||
)
|
||||
|
||||
// Add implements resource.Service.
|
||||
func (s *ResourceServiceImpl) Add(ctx context.Context, in *resource.Resource) (*resource.Resource, error) {
|
||||
if err := datasource.DBFromCtx(ctx).Save(in).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return in, nil
|
||||
}
|
||||
|
||||
// DeleteResource implements resource.Service.
|
||||
func (s *ResourceServiceImpl) DeleteResource(ctx context.Context, in *resource.DeleteResourceRequest) error {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// Search implements resource.Service.
|
||||
func (s *ResourceServiceImpl) Search(ctx context.Context, in *resource.SearchRequest) (*types.Set[*resource.Resource], error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
5
devcloud/cmdb/apps/secret/const.go
Normal file
5
devcloud/cmdb/apps/secret/const.go
Normal file
@ -0,0 +1,5 @@
|
||||
package secret
|
||||
|
||||
const (
|
||||
TASK_LABLE_SECRET_ID = "secret_id"
|
||||
)
|
@ -1 +1,31 @@
|
||||
package impl
|
||||
|
||||
import (
|
||||
"122.51.31.227/go-course/go18/devcloud/cmdb/apps/secret"
|
||||
"github.com/infraboard/mcube/v2/ioc"
|
||||
"github.com/infraboard/mcube/v2/ioc/config/datasource"
|
||||
)
|
||||
|
||||
func init() {
|
||||
ioc.Controller().Registry(&SecretServiceImpl{})
|
||||
}
|
||||
|
||||
var _ secret.Service = (*SecretServiceImpl)(nil)
|
||||
|
||||
type SecretServiceImpl struct {
|
||||
ioc.ObjectImpl
|
||||
}
|
||||
|
||||
func (s *SecretServiceImpl) Name() string {
|
||||
return secret.APP_NAME
|
||||
}
|
||||
|
||||
func (s *SecretServiceImpl) Init() error {
|
||||
if datasource.Get().AutoMigrate {
|
||||
err := datasource.DB().AutoMigrate(&secret.Secret{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
15
devcloud/cmdb/apps/secret/impl/impl_test.go
Normal file
15
devcloud/cmdb/apps/secret/impl/impl_test.go
Normal file
@ -0,0 +1,15 @@
|
||||
package impl_test
|
||||
|
||||
import (
|
||||
"122.51.31.227/go-course/go18/devcloud/cmdb/apps/secret"
|
||||
"122.51.31.227/go-course/go18/devcloud/cmdb/test"
|
||||
)
|
||||
|
||||
var (
|
||||
svc secret.Service
|
||||
)
|
||||
|
||||
func init() {
|
||||
test.DevelopmentSetUp()
|
||||
svc = secret.GetService()
|
||||
}
|
@ -1 +1,100 @@
|
||||
package impl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"122.51.31.227/go-course/go18/devcloud/cmdb/apps/secret"
|
||||
"github.com/infraboard/mcube/v2/exception"
|
||||
"github.com/infraboard/mcube/v2/ioc/config/datasource"
|
||||
"github.com/infraboard/mcube/v2/types"
|
||||
"github.com/infraboard/modules/task/apps/task"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// CreateSecret implements secret.Service.
|
||||
func (s *SecretServiceImpl) CreateSecret(ctx context.Context, in *secret.CreateSecretRequest) (*secret.Secret, error) {
|
||||
ins := secret.NewSecret(in)
|
||||
|
||||
// 需要加密
|
||||
if err := ins.EncryptedApiSecret(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// upsert, gorm save
|
||||
if err := datasource.DBFromCtx(ctx).Save(ins).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ins, nil
|
||||
}
|
||||
|
||||
// DescribeSecret implements secret.Service.
|
||||
func (s *SecretServiceImpl) DescribeSecret(ctx context.Context, in *secret.DescribeSecretRequeset) (*secret.Secret, error) {
|
||||
// 取出后,需要解密
|
||||
ins := &secret.Secret{}
|
||||
query := in.GormResourceFilter(datasource.DBFromCtx(ctx).Model(&secret.Secret{}))
|
||||
if err := query.Where("id = ?", in.Id).Take(ins).Error; err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return nil, exception.NewNotFound("secret %s not found", in.Id)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
ins.SetIsEncrypted(true)
|
||||
if err := ins.DecryptedApiSecret(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 解密过后的数据
|
||||
return ins, nil
|
||||
}
|
||||
|
||||
// QuerySecret implements secret.Service.
|
||||
func (s *SecretServiceImpl) QuerySecret(ctx context.Context, in *secret.QuerySecretRequest) (*types.Set[*secret.Secret], error) {
|
||||
set := types.New[*secret.Secret]()
|
||||
|
||||
query := in.GormResourceFilter(datasource.DBFromCtx(ctx).Model(&secret.Secret{}))
|
||||
err := query.Count(&set.Total).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = query.
|
||||
Order("create_at desc").
|
||||
Offset(int(in.ComputeOffset())).
|
||||
Limit(int(in.PageSize)).
|
||||
Find(&set.Items).
|
||||
Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return set, nil
|
||||
|
||||
}
|
||||
|
||||
// SyncResource implements secret.Service.
|
||||
// 资源同步接口
|
||||
func (s *SecretServiceImpl) SyncResource(ctx context.Context, in *secret.SyncResourceRequest) (*types.Set[*task.Task], error) {
|
||||
// 直接初始化并返回,避免警告
|
||||
taskSet := types.NewSet[*task.Task]()
|
||||
|
||||
// 查询Secret信息
|
||||
ins, err := s.DescribeSecret(ctx, secret.NewDescribeSecretRequeset(in.Id))
|
||||
if err != nil {
|
||||
return taskSet, err
|
||||
}
|
||||
|
||||
if !ins.GetEnabled() {
|
||||
return taskSet, fmt.Errorf("secret %s not enabled", ins.Name)
|
||||
}
|
||||
|
||||
// 获取syncer, 执行同步
|
||||
for _, rs := range ins.ResourceType {
|
||||
syncer := secret.GetSyncer(rs)
|
||||
for _, region := range ins.Regions {
|
||||
taskInfo := syncer.Sync(ctx, ins, region, rs)
|
||||
taskSet.Add(taskInfo)
|
||||
}
|
||||
}
|
||||
return taskSet, nil
|
||||
}
|
||||
|
59
devcloud/cmdb/apps/secret/impl/secret_test.go
Normal file
59
devcloud/cmdb/apps/secret/impl/secret_test.go
Normal file
@ -0,0 +1,59 @@
|
||||
package impl_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"122.51.31.227/go-course/go18/devcloud/cmdb/apps/resource"
|
||||
"122.51.31.227/go-course/go18/devcloud/cmdb/apps/secret"
|
||||
)
|
||||
|
||||
func TestCreateSecret(t *testing.T) {
|
||||
req := secret.NewCreateSecretRequest()
|
||||
req.Name = "腾讯云只读账号"
|
||||
req.Vendor = resource.VENDOR_TENCENT
|
||||
req.ApiKey = os.Getenv("TX_API_KEY")
|
||||
req.ApiSecret = os.Getenv("TX_API_SECRET")
|
||||
req.SetEnabled(true)
|
||||
req.ResourceType = append(req.ResourceType, resource.TYPE_VM)
|
||||
req.Regions = []string{"ap-shanghai", "ap-guangzhou"}
|
||||
ins, err := svc.CreateSecret(t.Context(), req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(ins)
|
||||
}
|
||||
|
||||
func TestQuerySecret(t *testing.T) {
|
||||
req := secret.NewQuerySecretRequest()
|
||||
set, err := svc.QuerySecret(t.Context(), req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(set)
|
||||
}
|
||||
|
||||
const (
|
||||
SECRET_ID = "e5aa1ad4-6069-397e-a7ed-a78b9cd2a93b"
|
||||
)
|
||||
|
||||
func TestDescribeSecret(t *testing.T) {
|
||||
req := secret.NewDescribeSecretRequeset(SECRET_ID)
|
||||
ins, err := svc.DescribeSecret(t.Context(), req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(ins)
|
||||
}
|
||||
|
||||
func TestSyncResource(t *testing.T) {
|
||||
req := secret.NewSyncResourceRequest(SECRET_ID)
|
||||
ins, err := svc.SyncResource(t.Context(), req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(ins)
|
||||
|
||||
time.Sleep(3 * time.Second)
|
||||
}
|
@ -4,10 +4,12 @@ import (
|
||||
"context"
|
||||
|
||||
"122.51.31.227/go-course/go18/devcloud/cmdb/apps/resource"
|
||||
"122.51.31.227/go-course/go18/devcloud/mcenter/apps/policy"
|
||||
"github.com/infraboard/mcube/v2/http/request"
|
||||
"github.com/infraboard/mcube/v2/ioc"
|
||||
"github.com/infraboard/mcube/v2/tools/pretty"
|
||||
"github.com/infraboard/mcube/v2/types"
|
||||
"github.com/infraboard/modules/task/apps/task"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -34,10 +36,8 @@ type Service interface {
|
||||
// 这个接口调用持续30分钟...
|
||||
// 需要拆解为异步任务: 用户调用了同步后, 里面返回, 这个同步任务在后台执行(Gorouties), 需要查询同步日志(Ws)
|
||||
|
||||
// 执行同步
|
||||
SyncResource(context.Context, *SyncResourceRequest) (*SyncResourceTask, error)
|
||||
// 查询同步日志
|
||||
QuerySyncLog(context.Context, *QuerySyncLogRequest) (*types.Set[*SyncRecord], error)
|
||||
// 使用task模块来执行异步任务, 通过TaskId查询异步任务状态
|
||||
SyncResource(context.Context, *SyncResourceRequest) (*types.Set[*task.Task], error)
|
||||
}
|
||||
|
||||
// 同步记录(task) 有状态
|
||||
@ -70,6 +70,7 @@ func NewQuerySecretRequest() *QuerySecretRequest {
|
||||
}
|
||||
|
||||
type QuerySecretRequest struct {
|
||||
policy.ResourceScope
|
||||
// 分页请求
|
||||
*request.PageRequest
|
||||
}
|
||||
@ -81,6 +82,7 @@ func NewDescribeSecretRequeset(id string) *DescribeSecretRequeset {
|
||||
}
|
||||
|
||||
type DescribeSecretRequeset struct {
|
||||
policy.ResourceScope
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"122.51.31.227/go-course/go18/devcloud/cmdb/apps/resource"
|
||||
"122.51.31.227/go-course/go18/devcloud/mcenter/apps/policy"
|
||||
"github.com/google/uuid"
|
||||
"github.com/infraboard/devops/pkg/model"
|
||||
"github.com/infraboard/mcube/v2/crypto/cbc"
|
||||
@ -28,7 +29,10 @@ func NewSecret(in *CreateSecretRequest) *Secret {
|
||||
|
||||
type Secret struct {
|
||||
model.Meta
|
||||
CreateSecretRequest `bson:"inline"`
|
||||
// 资源范围, Namespace是继承的, Scope是API添加的
|
||||
policy.ResourceLabel
|
||||
// 资源定义
|
||||
CreateSecretRequest
|
||||
}
|
||||
|
||||
func (s *Secret) TableName() string {
|
||||
@ -54,6 +58,8 @@ func NewCreateSecretRequest() *CreateSecretRequest {
|
||||
}
|
||||
|
||||
type CreateSecretRequest struct {
|
||||
// 是否启用
|
||||
Enabled *bool `json:"enabled" gorm:"column:enabled"`
|
||||
// 名称
|
||||
Name string `json:"name" gorm:"column:name"`
|
||||
// 尝试
|
||||
@ -76,8 +82,21 @@ type CreateSecretRequest struct {
|
||||
isEncrypted bool `gorm:"-"`
|
||||
}
|
||||
|
||||
func (r *CreateSecretRequest) SetIsEncrypted(v bool) {
|
||||
func (r *CreateSecretRequest) SetIsEncrypted(v bool) *CreateSecretRequest {
|
||||
r.isEncrypted = v
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *CreateSecretRequest) SetEnabled(v bool) *CreateSecretRequest {
|
||||
r.Enabled = &v
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *CreateSecretRequest) GetEnabled() bool {
|
||||
if r.Enabled == nil {
|
||||
return false
|
||||
}
|
||||
return *r.Enabled
|
||||
}
|
||||
|
||||
func (r *CreateSecretRequest) GetSyncLimit() int64 {
|
||||
|
34
devcloud/cmdb/apps/secret/sync.go
Normal file
34
devcloud/cmdb/apps/secret/sync.go
Normal file
@ -0,0 +1,34 @@
|
||||
package secret
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"122.51.31.227/go-course/go18/devcloud/cmdb/apps/resource"
|
||||
"github.com/infraboard/modules/task/apps/task"
|
||||
)
|
||||
|
||||
const (
|
||||
SYNCER_PREFIX = "syncer"
|
||||
)
|
||||
|
||||
var (
|
||||
syncers = map[string]Syncer{}
|
||||
)
|
||||
|
||||
func GetSyncerName(t resource.TYPE) string {
|
||||
return fmt.Sprintf("%s_%s", SYNCER_PREFIX, t)
|
||||
}
|
||||
|
||||
func GetSyncer(t resource.TYPE) Syncer {
|
||||
return syncers[fmt.Sprintf("%s_%s", SYNCER_PREFIX, t)]
|
||||
}
|
||||
|
||||
func RegistrySyncer(t resource.TYPE, s Syncer) {
|
||||
syncers[fmt.Sprintf("%s_%s", SYNCER_PREFIX, t)] = s
|
||||
}
|
||||
|
||||
type Syncer interface {
|
||||
// 资源同步
|
||||
Sync(ctx context.Context, ins *Secret, region string, rt resource.TYPE) *task.Task
|
||||
}
|
59
devcloud/cmdb/apps/secret/sync/data/vm.json
Normal file
59
devcloud/cmdb/apps/secret/sync/data/vm.json
Normal file
@ -0,0 +1,59 @@
|
||||
{
|
||||
"Response": {
|
||||
"InstanceSet": [
|
||||
{
|
||||
"BlueprintId": "lhbp-b46k6f98",
|
||||
"BundleId": "bundle_starter_mc_promo_med2_02",
|
||||
"CPU": 2,
|
||||
"CreatedTime": "2025-03-02T09:54:10Z",
|
||||
"ExpiredTime": "2026-03-02T09:54:10Z",
|
||||
"InitInvocationId": "",
|
||||
"InstanceChargeType": "PREPAID",
|
||||
"InstanceId": "lhins-dxvcse1s",
|
||||
"InstanceName": "Docker CE-MyRb",
|
||||
"InstanceRestrictState": "NORMAL",
|
||||
"InstanceState": "RUNNING",
|
||||
"InternetAccessible": {
|
||||
"InternetChargeType": "TRAFFIC_POSTPAID_BY_HOUR",
|
||||
"InternetMaxBandwidthOut": 4,
|
||||
"PublicIpAssigned": true
|
||||
},
|
||||
"IsolatedTime": null,
|
||||
"LatestOperation": "",
|
||||
"LatestOperationRequestId": "",
|
||||
"LatestOperationStartedTime": "2025-03-02T09:53:37Z",
|
||||
"LatestOperationState": "",
|
||||
"LoginSettings": {
|
||||
"KeyIds": []
|
||||
},
|
||||
"Memory": 2,
|
||||
"OsName": "Ubuntu Server 24.04 LTS 64bit",
|
||||
"Platform": "UBUNTU",
|
||||
"PlatformType": "LINUX_UNIX",
|
||||
"PrivateAddresses": [
|
||||
"10.0.4.9"
|
||||
],
|
||||
"PublicAddresses": [
|
||||
"122.51.31.227"
|
||||
],
|
||||
"PublicIpv6Addresses": [],
|
||||
"RenewFlag": "NOTIFY_AND_MANUAL_RENEW",
|
||||
"SupportIpv6Detail": {
|
||||
"Detail": "EFFECTIVE_IMMEDIATELY",
|
||||
"IsSupport": true,
|
||||
"Message": ""
|
||||
},
|
||||
"SystemDisk": {
|
||||
"DiskId": "lhdisk-adyw1bgo",
|
||||
"DiskSize": 50,
|
||||
"DiskType": "CLOUD_SSD"
|
||||
},
|
||||
"Tags": [],
|
||||
"Uuid": "dd452294-6c06-4d4e-ab5f-b5d74404b863",
|
||||
"Zone": "ap-shanghai-2"
|
||||
}
|
||||
],
|
||||
"RequestId": "9863afd3-47f4-4aa0-9e95-9b61ea3e5573",
|
||||
"TotalCount": 1
|
||||
}
|
||||
}
|
116
devcloud/cmdb/apps/secret/sync/vm.go
Normal file
116
devcloud/cmdb/apps/secret/sync/vm.go
Normal file
@ -0,0 +1,116 @@
|
||||
package sync
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"122.51.31.227/go-course/go18/devcloud/cmdb/apps/resource"
|
||||
"122.51.31.227/go-course/go18/devcloud/cmdb/apps/secret"
|
||||
"github.com/infraboard/mcube/v2/ioc"
|
||||
"github.com/infraboard/mcube/v2/ioc/config/log"
|
||||
"github.com/infraboard/mcube/v2/tools/ptr"
|
||||
"github.com/infraboard/modules/task/apps/event"
|
||||
"github.com/infraboard/modules/task/apps/task"
|
||||
"github.com/rs/zerolog"
|
||||
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||
lighthouse "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse/v20200324"
|
||||
)
|
||||
|
||||
func init() {
|
||||
ioc.Controller().Registry(&VmSyncerServiceImpl{})
|
||||
}
|
||||
|
||||
var _ secret.Syncer = (*VmSyncerServiceImpl)(nil)
|
||||
|
||||
type VmSyncerServiceImpl struct {
|
||||
ioc.ObjectImpl
|
||||
|
||||
log *zerolog.Logger
|
||||
}
|
||||
|
||||
func (s *VmSyncerServiceImpl) Name() string {
|
||||
return secret.GetSyncerName(resource.TYPE_VM)
|
||||
}
|
||||
|
||||
func (s *VmSyncerServiceImpl) Init() error {
|
||||
s.log = log.Sub(s.Name())
|
||||
secret.RegistrySyncer(resource.TYPE_VM, s)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Sync implements secret.Syncer.
|
||||
func (s *VmSyncerServiceImpl) Sync(ctx context.Context, ins *secret.Secret, region string, rs resource.TYPE) *task.Task {
|
||||
// 怎么使用对应secret 来完成, 用的腾讯的API
|
||||
// https://console.cloud.tencent.com/api/explorer?Product=cvm&Version=2017-03-12&Action=DescribeRegions
|
||||
// https://console.cloud.tencent.com/api/explorer?Product=lighthouse&Version=2020-03-24&Action=DescribeInstances
|
||||
return task.GetService().Run(ctx, task.NewFnTask(func(ctx context.Context, req any) error {
|
||||
taskInfo := task.GetTaskFromCtx(ctx)
|
||||
_, err := event.GetService().AddEvent(ctx, task.NewInfoEvent("同步开始", taskInfo.Id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer event.GetService().AddEvent(ctx, task.NewInfoEvent("同步结束", taskInfo.Id))
|
||||
|
||||
// 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
|
||||
// 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性
|
||||
// 以下代码示例仅供参考,建议采用更安全的方式来使用密钥
|
||||
// 请参见:https://cloud.tencent.com/document/product/1278/85305
|
||||
// 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
|
||||
credential := common.NewCredential(
|
||||
ins.ApiKey,
|
||||
ins.ApiSecret,
|
||||
)
|
||||
// 使用临时密钥示例
|
||||
// credential := common.NewTokenCredential("SecretId", "SecretKey", "Token")
|
||||
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
||||
cpf := profile.NewClientProfile()
|
||||
cpf.HttpProfile.Endpoint = "lighthouse.tencentcloudapi.com"
|
||||
// 实例化要请求产品的client对象,clientProfile是可选的
|
||||
// "ap-shanghai"
|
||||
client, _ := lighthouse.NewClient(credential, region, cpf)
|
||||
|
||||
// 实例化一个请求对象,每个接口都会对应一个request对象
|
||||
request := lighthouse.NewDescribeInstancesRequest()
|
||||
|
||||
// 返回的resp是一个DescribeInstancesResponse的实例,与请求对象对应
|
||||
response, err := client.DescribeInstances(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = event.GetService().AddEvent(ctx, task.NewInfoEvent("接口调用成功", taskInfo.Id).SetDetail(response.ToJsonString()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 获取出了实例的列表
|
||||
for _, vm := range response.Response.InstanceSet {
|
||||
// 转化为一个Resource对象
|
||||
res := resource.NewResource()
|
||||
res.Vendor = resource.VENDOR_TENCENT
|
||||
res.CredentialId = ins.Id
|
||||
res.Region = region
|
||||
res.ResourceType = resource.TYPE_VM
|
||||
res.Id = ptr.GetValue(vm.InstanceId)
|
||||
res.Name = ptr.GetValue(vm.InstanceName)
|
||||
res.Cpu = ptr.GetValue(vm.CPU)
|
||||
res.Memory = ptr.GetValue(vm.Memory)
|
||||
res.SystemStorage = ptr.GetValue(vm.SystemDisk.DiskSize)
|
||||
res.Extra["os_name"] = ptr.GetValue(vm.OsName)
|
||||
res.PrivateAddress = ptr.GetArrayValue(vm.PrivateAddresses)
|
||||
res.PublicAddress = ptr.GetArrayValue(vm.PublicAddresses)
|
||||
res.Phase = ptr.GetValue(vm.InstanceState)
|
||||
res, err := resource.GetService().Add(ctx, res)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = event.GetService().AddEvent(ctx, task.NewInfoEvent(fmt.Sprintf("资源%s同步成功", res.Name), taskInfo.Id).SetDetail(res.String()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}, ins).SetAsync(true).SetLabel(secret.TASK_LABLE_SECRET_ID, ins.Id))
|
||||
}
|
21
devcloud/cmdb/test/setup.go
Normal file
21
devcloud/cmdb/test/setup.go
Normal file
@ -0,0 +1,21 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/infraboard/mcube/v2/ioc"
|
||||
// 要注册哪些对象, Book, Comment
|
||||
|
||||
// 加载的业务对象
|
||||
_ "122.51.31.227/go-course/go18/devcloud/cmdb/apps"
|
||||
// task模块
|
||||
_ "github.com/infraboard/modules/task/apps"
|
||||
// _ "122.51.31.227/go-course/go18/devcloud/mcenter/apps"
|
||||
// _ "122.51.31.227/go-course/go18/devcloud/mpaas/apps"
|
||||
)
|
||||
|
||||
func DevelopmentSetUp() {
|
||||
// import 后自动执行的逻辑
|
||||
// 工具对象的初始化, 需要的是绝对路径
|
||||
ioc.DevelopmentSetupWithPath(os.Getenv("CONFIG_PATH"))
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
database = "devcloud_go18"
|
||||
username = "root"
|
||||
password = "123456"
|
||||
auto_migrate = false
|
||||
auto_migrate = true
|
||||
debug = false
|
||||
|
||||
[mongo]
|
||||
|
@ -0,0 +1,3 @@
|
||||
|
||||
TX_API_KEY=
|
||||
TX_API_SECRET=
|
8
go.mod
8
go.mod
@ -9,12 +9,14 @@ require (
|
||||
github.com/gin-gonic/gin v1.10.0
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/infraboard/devops v0.0.6
|
||||
github.com/infraboard/mcube/v2 v2.0.61
|
||||
github.com/infraboard/modules v0.0.12
|
||||
github.com/infraboard/mcube/v2 v2.0.63
|
||||
github.com/infraboard/modules v0.0.20
|
||||
github.com/rs/xid v1.6.0
|
||||
github.com/rs/zerolog v1.34.0
|
||||
github.com/segmentio/kafka-go v0.4.47
|
||||
github.com/stretchr/testify v1.10.0
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1138
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.1134
|
||||
go.mongodb.org/mongo-driver v1.17.3
|
||||
golang.org/x/crypto v0.38.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
@ -80,6 +82,7 @@ require (
|
||||
github.com/prometheus/common v0.63.0 // indirect
|
||||
github.com/prometheus/procfs v0.16.0 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||
github.com/spf13/cobra v1.9.1 // indirect
|
||||
github.com/spf13/pflag v1.0.6 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
@ -117,5 +120,6 @@ require (
|
||||
modernc.org/mathutil v1.5.0 // indirect
|
||||
modernc.org/memory v1.5.0 // indirect
|
||||
modernc.org/sqlite v1.23.1 // indirect
|
||||
resty.dev/v3 v3.0.0-beta.2 // indirect
|
||||
sigs.k8s.io/yaml v1.4.0 // indirect
|
||||
)
|
||||
|
17
go.sum
17
go.sum
@ -97,10 +97,10 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/infraboard/devops v0.0.6 h1:oo7RfRBxu9hbI/+bYzXuX40BfG1hRyVtxC0fBhoFGBU=
|
||||
github.com/infraboard/devops v0.0.6/go.mod h1:Ac+W3wFy5pG9EH7f1W8DxiAZRhnTDFHrp27WKkYnNoU=
|
||||
github.com/infraboard/mcube/v2 v2.0.61 h1:al8Z+poXXOjfTIAY48ujFzV1uYzH/N7/xmve/ZXArbo=
|
||||
github.com/infraboard/mcube/v2 v2.0.61/go.mod h1:TbYs8cnD8Cg19sTdU0D+vqWAN+LzoxhMYWmAC2pfJkQ=
|
||||
github.com/infraboard/modules v0.0.12 h1:vQqm+JwzmhL+hcD9SV+WVlp9ecInc7NsbGahcTmJ0Wk=
|
||||
github.com/infraboard/modules v0.0.12/go.mod h1:NdgdH/NoeqibJmFPn9th+tisMuR862/crbXeH4FPMaU=
|
||||
github.com/infraboard/mcube/v2 v2.0.63 h1:OUmDajfLAQ1LUVEutCSRbDIQItyLSPHYWXUJLO6IbaE=
|
||||
github.com/infraboard/mcube/v2 v2.0.63/go.mod h1:TbYs8cnD8Cg19sTdU0D+vqWAN+LzoxhMYWmAC2pfJkQ=
|
||||
github.com/infraboard/modules v0.0.20 h1:5tNT9eSkTBCx4OA+7sZr1Bf+miOGf9Zft2X/sESrlpE=
|
||||
github.com/infraboard/modules v0.0.20/go.mod h1:H2kRn3Ksp+3OMt9yYB2imNR2RJgSytTVt9WFP8XpDRQ=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD7Fpv9jeVMgy/+Ec0mtnmYuImjTz6dtDA=
|
||||
@ -181,6 +181,8 @@ github.com/prometheus/procfs v0.16.0/go.mod h1:8veyXUu3nGP7oaCxhX6yeaM5u4stL2FeM
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||
github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
|
||||
@ -207,6 +209,11 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1134/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1138 h1:eMVp9kzjBptP3K0xaUUS68dF5nNTFLbom3uQREaqftM=
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1138/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.1134 h1:+pjecViStkJrHVbZs+OtCFULfAoD0UOxAZJVDwBjKC8=
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.1134/go.mod h1:vp2EZhERa7VxNFUlntLv7JDu3OD/pbpUpduFf5BGSfQ=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
|
||||
@ -353,5 +360,7 @@ modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
|
||||
modernc.org/sqlite v1.23.1 h1:nrSBg4aRQQwq59JpvGEQ15tNxoO5pX/kUjcRNwSAGQM=
|
||||
modernc.org/sqlite v1.23.1/go.mod h1:OrDj17Mggn6MhE+iPbBNf7RGKODDE9NFT0f3EwDzJqk=
|
||||
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
|
||||
resty.dev/v3 v3.0.0-beta.2 h1:xu4mGAdbCLuc3kbk7eddWfWm4JfhwDtdapwss5nCjnQ=
|
||||
resty.dev/v3 v3.0.0-beta.2/go.mod h1:OgkqiPvTDtOuV4MGZuUDhwOpkY8enjOsjjMzeOHefy4=
|
||||
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
|
||||
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
|
||||
|
3
skills/html/README.md
Normal file
3
skills/html/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# HTML
|
||||
|
||||
vscode 插件: open in browser
|
BIN
skills/html/images/1.jpeg
Normal file
BIN
skills/html/images/1.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 181 KiB |
BIN
skills/html/images/2.jpeg
Normal file
BIN
skills/html/images/2.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 85 KiB |
39
skills/html/index.css
Normal file
39
skills/html/index.css
Normal file
@ -0,0 +1,39 @@
|
||||
/* p {
|
||||
color: blue;
|
||||
} */
|
||||
|
||||
/* . class */
|
||||
.red {
|
||||
color: red;
|
||||
}
|
||||
|
||||
/* # 表示这是一个id选择器 */
|
||||
#input01 {
|
||||
width: 400px;
|
||||
}
|
||||
|
||||
/* ul>li:first-child {
|
||||
font-weight: 600;
|
||||
} */
|
||||
|
||||
|
||||
ul li:hover {
|
||||
color: red;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
img {
|
||||
width: 220px;
|
||||
height: 220px;
|
||||
object-fit: cover; /* 裁剪成正方形 */
|
||||
border-radius: 4px; /* 可选:圆角 */
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
.img-warppter {
|
||||
height: 300px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
109
skills/html/index.html
Normal file
109
skills/html/index.html
Normal file
@ -0,0 +1,109 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Document</title>
|
||||
<link rel="stylesheet" type="text/css" href="./index.css" />
|
||||
<!-- <style>
|
||||
p {
|
||||
color: blue;
|
||||
}
|
||||
</style> -->
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="title01">HTML 语法介绍</h1>
|
||||
<p class="red">段落</p>
|
||||
<p>段落</p>
|
||||
<span class="red">文字A</span>
|
||||
<br />
|
||||
<span class="red">文字B</span>
|
||||
<br />
|
||||
<form action="demo_form.php" method="get">
|
||||
First name: <input id="input01" type="text" name="fname" /><br />
|
||||
Last name: <input type="text" name="lname" /><br />
|
||||
<input type="submit" value="提交" />
|
||||
</form>
|
||||
|
||||
<iframe
|
||||
src="https://www.baidu.com"
|
||||
style="width: 800px; height: 400"
|
||||
></iframe>
|
||||
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Month</th>
|
||||
<th>Savings</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>January</td>
|
||||
<td>$100</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>February</td>
|
||||
<td>$80</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div style="width: 400px; height: 400; background-color: aqua">
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Month</th>
|
||||
<th>Savings</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>January</td>
|
||||
<td>$100</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>February</td>
|
||||
<td>$80</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br />
|
||||
<p>这是一个段落</p>
|
||||
</div>
|
||||
<hr />
|
||||
<div style="width: 400px; height: 400; background-color: aqua">
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Month</th>
|
||||
<th>Savings</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>January</td>
|
||||
<td>$100</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>February</td>
|
||||
<td>$80</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br />
|
||||
<p>这是一个段落</p>
|
||||
</div>
|
||||
|
||||
<span>span1</span>
|
||||
<span>span2</span>
|
||||
|
||||
<br />
|
||||
<ul id="list_menu" class="ul_class">
|
||||
<li id="coffee">Coffee</li>
|
||||
<li>Tea</li>
|
||||
<li>Milk</li>
|
||||
<div>
|
||||
<li>绿茶</li>
|
||||
<li>红茶</li>
|
||||
</div>
|
||||
</ul>
|
||||
|
||||
<div class="img-warppter">
|
||||
<img src="./images/1.jpeg" alt="" />
|
||||
<img src="./images/2.jpeg" alt="" />
|
||||
<img src="./images/1.jpeg" alt="" />
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById("title01").style.color = "red";
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
5
skills/javascript/README.md
Normal file
5
skills/javascript/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# js
|
||||
|
||||
[课件](https://gitee.com/infraboard/go-course/blob/master/day19/javascript.md)
|
||||
|
||||
安装Code Runner插件
|
16
skills/javascript/app.mjs
Normal file
16
skills/javascript/app.mjs
Normal file
@ -0,0 +1,16 @@
|
||||
// 唯一的全局变量MYAPP:
|
||||
var MYAPP = {};
|
||||
|
||||
// 其他变量:
|
||||
MYAPP.name = 'myapp';
|
||||
MYAPP.version = 1.0;
|
||||
|
||||
// 其他函数:
|
||||
MYAPP.foo = function () {
|
||||
return 'foo';
|
||||
};
|
||||
|
||||
// export {MYAPP}
|
||||
|
||||
// MYAPP --> default
|
||||
export default MYAPP
|
57
skills/javascript/async.drawio
Normal file
57
skills/javascript/async.drawio
Normal file
@ -0,0 +1,57 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="0WS3t2Fnvb50-m555Ywn" name="第 1 页">
|
||||
<mxGraphModel dx="1176" dy="389" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0"/>
|
||||
<mxCell id="1" parent="0"/>
|
||||
<mxCell id="2" value="事件触发器" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="180" y="70" width="40" height="410" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="3" value="fna" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="240" y="90" width="120" height="50" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="4" value="fnb" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="360" y="120" width="120" height="50" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="5" value="fnc" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="480" y="140" width="120" height="50" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="6" value="fnd" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="600" y="160" width="120" height="50" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="7" value="async fna" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="280" y="270" width="120" height="50" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="8" value="async fnb" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="280" y="350" width="120" height="50" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="9" value="async fnc" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="280" y="430" width="120" height="50" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="10" value="async fnd" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="280" y="510" width="120" height="50" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="13" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="11" target="7">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="16" value="await" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="13">
|
||||
<mxGeometry x="0.3011" y="1" relative="1" as="geometry">
|
||||
<mxPoint as="offset"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="15" style="edgeStyle=none;html=1;exitX=0;exitY=0.75;exitDx=0;exitDy=0;entryX=1;entryY=1;entryDx=0;entryDy=0;" edge="1" parent="1" source="11" target="8">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="11" value="excutor(<div>aysnc executor</div><div><br></div><div>event pool)</div>" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="591" y="270" width="120" height="290" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="12" style="edgeStyle=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0.017;entryY=0.31;entryDx=0;entryDy=0;entryPerimeter=0;" edge="1" parent="1" source="7" target="11">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="14" style="edgeStyle=none;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=-0.025;entryY=0.652;entryDx=0;entryDy=0;entryPerimeter=0;" edge="1" parent="1" source="8" target="11">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
69
skills/javascript/promise.js
Normal file
69
skills/javascript/promise.js
Normal file
@ -0,0 +1,69 @@
|
||||
function testApiCall(success, failed) {
|
||||
var timeOut = Math.random() * 2;
|
||||
console.log('set timeout to: ' + timeOut + ' seconds.');
|
||||
setTimeout(function () {
|
||||
if (timeOut < 1) {
|
||||
console.log('call resolve()...');
|
||||
success('200 OK');
|
||||
}
|
||||
else {
|
||||
console.log('call reject()...');
|
||||
failed('timeout in ' + timeOut + ' seconds.');
|
||||
}
|
||||
}, timeOut * 1000);
|
||||
}
|
||||
|
||||
// 通过回调实现的异步方案
|
||||
// fna()
|
||||
// fnb()
|
||||
// fnc()
|
||||
console.log('start ...')
|
||||
testApiCall(
|
||||
// success callback
|
||||
(data) => {
|
||||
console.log(data)
|
||||
},
|
||||
// failed callback
|
||||
(error) => {
|
||||
console.log(error)
|
||||
}
|
||||
)
|
||||
console.log('end ...')
|
||||
|
||||
// fna(fnb_sucess(fnc_success(fnd_success)), fnb_error(fnc_error(fnd_error)))
|
||||
|
||||
// promise 封装技术, 他让异步成为一种标准, 使用promise的标准方式来处理异常
|
||||
// promise 像一个接口,他约束了 excutor对象的 实现方式
|
||||
var p1 = new Promise(testApiCall)
|
||||
// p1.then((data) => {
|
||||
// console.log(data)
|
||||
// // p2.then().catch().finally()
|
||||
// }).catch((error) => {
|
||||
// console.log(error)
|
||||
// }).finally(() => {
|
||||
// console.log('finnal')
|
||||
// })
|
||||
|
||||
|
||||
// 异步等待
|
||||
// 以同步编程的方式,来实现异步代码
|
||||
var async_await = async () => {
|
||||
try {
|
||||
const resp = await p1
|
||||
console.log(resp)
|
||||
|
||||
// const res2 = await p2
|
||||
// console.log(resp2)
|
||||
|
||||
// const res3 = await p3
|
||||
// console.log(resp2)
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
}
|
||||
|
||||
async_await()
|
||||
|
||||
|
||||
|
||||
|
84
skills/javascript/test.js
Normal file
84
skills/javascript/test.js
Normal file
@ -0,0 +1,84 @@
|
||||
// function sum (x , y) {
|
||||
// return x + y
|
||||
// }
|
||||
|
||||
// console.log(sum(1, 10))
|
||||
|
||||
// var person = {name: '小明', age: 23}
|
||||
|
||||
// console.log(person)
|
||||
|
||||
// person.greet = function() {
|
||||
// console.log(`hello, my name is ${this.name}, age ${this.age}`)
|
||||
// }
|
||||
// person.greet()
|
||||
|
||||
|
||||
// var name = '李四'
|
||||
// var age = 23
|
||||
|
||||
// function greet () {
|
||||
// console.log(`hello, my name is ${name}, age ${age}`)
|
||||
// }
|
||||
|
||||
// greet()
|
||||
|
||||
|
||||
// fn = function (x , y) {
|
||||
// return x + y
|
||||
// }
|
||||
// console.log(fn(1,2))
|
||||
|
||||
|
||||
// fn = (x, y) => {
|
||||
// return x + y
|
||||
// }
|
||||
// console.log(fn(1,2))
|
||||
|
||||
// fn = (x, y) => { return x + y}
|
||||
// console.log(fn(1,2))
|
||||
|
||||
// fn = (x, y) => x + y
|
||||
// console.log(fn(1,2))
|
||||
|
||||
// pow = x => x * x
|
||||
|
||||
// console.log(pow(100))
|
||||
|
||||
// pkg
|
||||
import {firstName, sum as my_sum} from './tool.mjs'
|
||||
console.log(my_sum(1,10))
|
||||
console.log(firstName)
|
||||
|
||||
// pkg.
|
||||
// import { MYAPP } from './app.mjs'
|
||||
// console.log(MYAPP.version)
|
||||
|
||||
|
||||
|
||||
// pkg
|
||||
// import { default as MYAPP } from './app.mjs'
|
||||
import appPKg from './app.mjs'
|
||||
console.log(appPKg.name)
|
||||
|
||||
// for item := rang a {}
|
||||
var a = ['A', 'B', 'C'];
|
||||
for (var item of a) {
|
||||
// fn(item)
|
||||
console.log(item)
|
||||
}
|
||||
|
||||
// for k,v := range o {}
|
||||
var o = {
|
||||
name: 'Jack',
|
||||
age: 20,
|
||||
city: 'Beijing'
|
||||
};
|
||||
for (var item of Object.keys(o)) {
|
||||
console.log(item, o[item])
|
||||
}
|
||||
|
||||
// forEach
|
||||
a.forEach((item) => {
|
||||
console.log(item)
|
||||
})
|
10
skills/javascript/tool.mjs
Normal file
10
skills/javascript/tool.mjs
Normal file
@ -0,0 +1,10 @@
|
||||
// export var sum = (x, y) => {return x + y}
|
||||
export function sum(x, y) {
|
||||
return x + y
|
||||
}
|
||||
|
||||
var firstName = 'Michael';
|
||||
var lastName = 'Jackson';
|
||||
var year = 1958;
|
||||
|
||||
export {firstName, lastName, year}
|
@ -116,7 +116,7 @@ func TestReadMessage(t *testing.T) {
|
||||
GroupID: "devcloud-go18-audit",
|
||||
// 可以指定Partition消费消息
|
||||
// Partition: 0,
|
||||
Topic: "audit_go18",
|
||||
Topic: "task_run_events",
|
||||
MinBytes: 10e3, // 10KB
|
||||
MaxBytes: 10e6, // 10MB
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user