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

feature機能 #27

Open
meian opened this issue May 8, 2024 · 0 comments
Open

feature機能 #27

meian opened this issue May 8, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@meian
Copy link
Owner

meian commented May 8, 2024

個別の実装を事前に定義して任意にmain.goに取り込める機能の追加

例(イメージ)

featureの登録

以下のコマンドでfeatureとして扱うパーツを登録する。
一旦登録するところを優先するけど、いずれはコンパイルチェックもできるようにしたい

atgo feature add zero --file zero.go
# 他のfeatureを参照する場合
atgo feature add max --file max.go --use zero

feature間の参照は後付けでも良いかも

  • max.go
package main

import (
  	"golang.org/x/exp/constraints"
)

// max returns the max value in s.
func max[T constraints.Ordered](s ...T) T {
	switch len(s) {
	case 0:
		return zero[T]()
	case 1:
		return s[0]
	}
	m := s[0]
	for _, v := range s[1:] {
		if v > m {
			m = v
		}
	}
	return m
}
  • zero.go
package main

import (
  	"golang.org/x/exp/constraints"
)

// zero returns the zero value of T.
func zero[T any]() T {
	var zero T
	return zero
}

featureの利用

atgo feature use max

とすると、main.go に max.go とそこから参照される zero.go の内容が追加される
この時に

  • importパッケージは現在の内容とfeature内の内容を比較して足りないものだけが登録されるようにする
  • (将来的に)feature内のimportパッケージがmain.goとかぶってた場合は自動的にパッケージ名のエイリアスを利用できるようにする
@meian meian added the enhancement New feature or request label May 8, 2024
@meian meian self-assigned this May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant