Skip to content

🚀 InitSatis

初始化一个新的 Satis 仓库:创建目录并生成基础 satis.json 配置。是 CreateSatisConfig 的目录化封装。

何时使用

当需要快速搭建一个 Satis 私有仓库骨架时使用,一步完成目录创建与配置文件写入。

签名

go
func (c *Composer) InitSatis(name string, homepage string, dir string) error

参数

参数类型说明
namestring仓库名称,例如 my-company/composer
homepagestring仓库主页 URL
dirstring目标目录;传空字符串则默认为 satis

返回值

返回值类型说明
唯一返回值error创建目录或写配置失败时返回

默认行为

dir 为空时使用 satis 作为目录;目录不存在会自动创建(权限 0755),配置写入 <dir>/satis.json

示例

go
package main

import (
	"log"

	"github.com/scagogogo/composer-skills/pkg/composer"
)

func main() {
	comp, err := composer.New(composer.DefaultOptions())
	if err != nil {
		log.Fatalf("初始化失败: %v", err)
	}

	if err := comp.InitSatis(
		"my-company/composer",
		"https://composer.example.com",
		"satis",
	); err != nil {
		log.Fatalf("初始化 Satis 失败: %v", err)
	}
}

进阶

基于 MIT 许可证发布