Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enhance default_extension_go for template mode #88

Merged
merged 7 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/build_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ jobs:
go-version: "stable"
cache: false

- name: Set ulimit and sysctl
run: |
# Because there are concurrent test cases which involves many
# concurrent socket connections, we need to enlarge the maximum number
# of the opened file descriptor.
ulimit -n 102400

# Because there are concurrent test cases which will create many
# concurrent connections simutaneously, we increase the TCP listening
# backlog value to 8192.
sudo sysctl -w kern.ipc.somaxconn=8192
shell: bash

- name: Install tools and dependencies
run: |

Expand Down Expand Up @@ -130,6 +143,19 @@ jobs:
go-version: "stable"
cache: false

- name: Set ulimit and sysctl
run: |
# Because there are concurrent test cases which involves many
# concurrent socket connections, we need to enlarge the maximum number
# of the opened file descriptor.
ulimit -n 102400

# Because there are concurrent test cases which will create many
# concurrent connections simutaneously, we increase the TCP listening
# backlog value to 8192.
sudo sysctl -w kern.ipc.somaxconn=8192
shell: bash

- name: Install tools and dependencies
run: |

Expand Down
7 changes: 6 additions & 1 deletion packages/core_extensions/default_extension_go/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ ten_package("default_extension_go") {
package_kind = "extension"

resources = [
"default_extension.go",
"extension.go",
"extension.go.tent",
"go_release.mod.tent=>go.mod.tent",
"go_release.mod=>go.mod",
"manifest.json",
"manifest.json.tent",
"property.json",
"README.md",
"README.md.tent",
"README-CN.md",
"README-CN.md.tent",
]

deps = [ "//core/src/ten_runtime" ]
Expand Down
29 changes: 29 additions & 0 deletions packages/core_extensions/default_extension_go/README-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# default_extension_go

<!-- 一句话介绍 -->

## 主要功能

<!-- 主要功能介绍 -->

- XXX 功能

## API

参考 [manifest.json](manifest.json) 中的 `api` 定义及 [property.json](property.json) 中的默认值。

<!-- 注:API 需要额外说明时,可以在此进行更详细的描述,或者 link 到额外的 API-CN.md 文档 -->

## 本地开发

### 构建

<!-- 构建说明 -->

### Unit test

<!-- 单元测试说明 -->

## 其他

<!-- 其他相关介绍 -->
29 changes: 29 additions & 0 deletions packages/core_extensions/default_extension_go/README-CN.md.tent
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# {{package_name}}

<!-- 一句话介绍 -->

## 主要功能

<!-- 主要功能介绍 -->

- XXX 功能

## API

参考 [manifest.json](manifest.json) 中的 `api` 定义及 [property.json](property.json) 中的默认值。

<!-- 注:API 需要额外说明时,可以在此进行更详细的描述,或者 link 到额外的 API-CN.md 文档 -->

## 本地开发

### 构建

<!-- 构建说明 -->

### Unit test

<!-- 单元测试说明 -->

## 其他

<!-- 其他相关介绍 -->
29 changes: 29 additions & 0 deletions packages/core_extensions/default_extension_go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# default_extension_go

<!-- brief introduction for the extension -->

## Features

<!-- main features introduction -->

- xxx feature

## API

Refer to `api` definition in [manifest.json] and default values in [property.json](property.json).

<!-- Additional API.md can be referred to if extra introduction needed -->

## Development

### Build

<!-- build dependencies and steps -->

### Unit test

<!-- how to do unit test for the extension -->

## Misc

<!-- others if applicable -->
29 changes: 29 additions & 0 deletions packages/core_extensions/default_extension_go/README.md.tent
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# {{package_name}}

<!-- brief introduction for the extension -->

## Features

<!-- main features introduction -->

- xxx feature

## API

Refer to `api` definition in [manifest.json] and default values in [property.json](property.json).

<!-- Additional API.md can be referred to if extra introduction needed -->

## Development

### Build

<!-- build dependencies and steps -->

### Unit test

<!-- how to do unit test for the extension -->

## Misc.

<!-- others if applicable -->
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// name. However, it is not common in Go.
//

package defaultextension
package default_extension_go

import (
"fmt"
Expand All @@ -20,30 +20,29 @@ type defaultExtension struct {
ten.DefaultExtension
}

func newDefaultExtension(name string) ten.Extension {
func newExtension(name string) ten.Extension {
return &defaultExtension{}
}

func (p *defaultExtension) OnStart(tenEnv ten.TenEnv) {
func (e *defaultExtension) OnStart(tenEnv ten.TenEnv) {
tenEnv.LogDebug("OnStart")

tenEnv.OnStartDone()
}

func (p *defaultExtension) OnStop(tenEnv ten.TenEnv) {
func (e *defaultExtension) OnStop(tenEnv ten.TenEnv) {
tenEnv.LogDebug("OnStop")

tenEnv.OnStopDone()
}

func (p *defaultExtension) OnCmd(
func (e *defaultExtension) OnCmd(
tenEnv ten.TenEnv,
cmd ten.Cmd,
) {
tenEnv.LogDebug("OnCmd")

cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk)
cmdResult.SetPropertyString("detail", "This is default go extension.")
tenEnv.ReturnResult(cmdResult, cmd)
}

Expand All @@ -53,6 +52,6 @@ func init() {
// Register addon
ten.RegisterAddonAsExtension(
"default_extension_go",
ten.NewDefaultExtensionAddon(newDefaultExtension),
ten.NewDefaultExtensionAddon(newExtension),
)
}
57 changes: 57 additions & 0 deletions packages/core_extensions/default_extension_go/extension.go.tent
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// This file is part of TEN Framework, an open source project.
// Licensed under the Apache License, Version 2.0.
// See the LICENSE file for more information.
//
// Note that this is just an example extension written in the GO programming
// language, so the package name does not equal to the containing directory
// name. However, it is not common in Go.
//

package {{package_name}}

import (
"fmt"

"ten_framework/ten"
)

type {{class_name_prefix}}Extension struct {
ten.DefaultExtension
}

func newExtension(name string) ten.Extension {
return &{{class_name_prefix}}Extension{}
}

func (e *{{class_name_prefix}}Extension) OnStart(tenEnv ten.TenEnv) {
tenEnv.LogDebug("OnStart")

tenEnv.OnStartDone()
}

func (e *{{class_name_prefix}}Extension) OnStop(tenEnv ten.TenEnv) {
tenEnv.LogDebug("OnStop")

tenEnv.OnStopDone()
}

func (e *{{class_name_prefix}}Extension) OnCmd(
tenEnv ten.TenEnv,
cmd ten.Cmd,
) {
tenEnv.LogDebug("OnCmd")

cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk)
tenEnv.ReturnResult(cmdResult, cmd)
}

func init() {
fmt.Println("{{package_name}} extension init")

// Register addon
ten.RegisterAddonAsExtension(
"{{package_name}}",
ten.NewDefaultExtensionAddon(newExtension),
)
}
2 changes: 1 addition & 1 deletion packages/core_extensions/default_extension_go/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module extension
module default_extension_go

go 1.18

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module extension
module default_extension_go

go 1.18

Expand Down
Loading