提交 887a9d7d 编写于 作者: J Jason

可以创建TCP服务了,并且正常监听

上级 1303306f
......@@ -42,7 +42,7 @@ func (c *Channel) Open() error {
func (c *Channel) Dial() error {
conn, err := net.Dial(c.Net, c.Addr)
if err != nil {
log.Println(err)
return err
}
go c.receive(conn)
......
......@@ -11,16 +11,10 @@ import (
var channels sync.Map
var connections sync.Map
//
//func init() {
// channels = new(sync.Map)
// connections = new(sync.Map)
//}
func Channels() []*types.Channel {
cs := make([]*types.Channel, 0)
func Channels() []*Channel {
cs := make([]*Channel, 0)
channels.Range(func(key, value interface{}) bool {
cs = append(cs, value.(*types.Channel))
cs = append(cs, value.(*Channel))
return true
})
return cs
......
<p>channel-edit works!</p>
<form nz-form nzLayout="horizontal" [formGroup]="validateForm" (ngSubmit)="submit()">
<nz-form-item>
<nz-form-label>名称</nz-form-label>
<nz-form-control nzErrorTip="请输入名称">
<input nz-input formControlName="name" placeholder="名称" />
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label>序列号</nz-form-label>
<nz-form-control nzErrorTip="请输入序列号">
<input nz-input formControlName="serial" placeholder="序列号" />
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label>网络类型</nz-form-label>
<nz-form-control nzErrorTip="请输入类型">
<input nz-input formControlName="net" placeholder="下拉" />
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label>地址</nz-form-label>
<nz-form-control nzErrorTip="请输入地址">
<input nz-input formControlName="addr" placeholder=":1843" />
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label>服务端</nz-form-label>
<nz-form-control nzErrorTip="请勾选">
<label nz-checkbox formControlName="is_server">
<span>启用</span>
</label>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label>心跳</nz-form-label>
<nz-form-control nzErrorTip="请勾选">
<label nz-checkbox formControlName="heart_beat.enable">
<span>启用</span>
</label>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label>注册包</nz-form-label>
<nz-form-control nzErrorTip="请勾选">
<label nz-checkbox formControlName="register.enable">
<span>启用</span>
</label>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-control>
<button nz-button nzType="primary">保存</button>
</nz-form-control>
</nz-form-item>
</form>
import {Component, Input, OnInit} from '@angular/core';
import {ApiService} from '../../api.service';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {NzDrawerRef} from 'ng-zorro-antd';
@Component({
selector: 'app-channel-edit',
......@@ -7,11 +10,68 @@ import {Component, Input, OnInit} from '@angular/core';
})
export class ChannelEditComponent implements OnInit {
@Input() channel = {};
@Input() channel: any = {};
constructor() { }
validateForm!: FormGroup;
constructor(private as: ApiService, private fb: FormBuilder, private drawerRef: NzDrawerRef<string>) {
}
ngOnInit(): void {
this.initForm({});
if (this.channel.id) {
this.as.get('channel/' + this.channel.id).subscribe(res => {
this.channel = res.data;
this.initForm(this.channel);
});
}
}
submit(): void {
for (const i in this.validateForm.controls) {
this.validateForm.controls[i].markAsDirty();
this.validateForm.controls[i].updateValueAndValidity();
}
if (!this.validateForm.valid) {
return;
}
if (this.channel.id) {
this.as.put('channel/' + this.channel.id, this.validateForm.value).subscribe(res => {
console.log(res);
// TODO 修改成功
this.drawerRef.close(res.data);
});
} else {
this.as.post('channel', this.validateForm.value).subscribe(res => {
console.log(res);
// TODO 保存成功
this.drawerRef.close(res.data);
});
}
}
initForm(item): void {
if (!item.register)
item.register = {};
if (!item.heart_beat)
item.heart_beat = {};
this.validateForm = this.fb.group({
name: [item.name, [Validators.required]],
// tags: [item.tags],
serial: [item.serial],
net: [item.net, [Validators.required]],
addr: [item.addr, [Validators.required]],
is_server: [item.is_server],
disabled: [item.disabled],
'register.enable': [item.register.enable],
'register.regex': [item.register.regex],
'heart_beat.enable': [item.heart_beat.enable],
'heart_beat.interval': [item.heart_beat.interval],
'heart_beat.content': [item.heart_beat.content],
});
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册