Pārlūkot izejas kodu

update documentation.

ZRY 2 mēneši atpakaļ
vecāks
revīzija
4c3753e2b6
1 mainītis faili ar 81 papildinājumiem un 0 dzēšanām
  1. 81 0
      docs/ngvfs_docs.typ

+ 81 - 0
docs/ngvfs_docs.typ

@@ -120,6 +120,87 @@
         
         `The system cannot find the path specified.`
 
+= 主机接口
+
+这部分是关于主机golang库的文档。
+
+该库位于 `openngvfs` 目录,包名 `git.swzry.com/zry/openNGVFS/openngvfs`。
+
+以下为主机部分的示例代码,更完整的示例代码可以参考
+`testing/standalone-test-0001/go`。
+
+```go
+func main() {	
+  // Init logger.
+  logger := hiedalog.NewHiedaLogger()
+	consoleBke := hiedabke_console.NewConsoleBackend(os.Stderr)
+	logger.AddBackend(
+    consoleBke,
+    logger.LevelFilter.NameToID(hiedalog.DLN_DEBUG),
+  )
+  // Create openNGVFS object.
+	fs := ngvfs.NewOpenNagaeVFS(logger)
+  // Create Context.
+	ctx := context.Background()
+  // root is the root path of this program.
+  root := "/home/satori/openngvfs_test_root/"
+  // Init openNGVFS.
+  // "test" is app name of this program.
+	err := fs.Init(ctx, root, "test")
+	if err != nil {
+		fmt.Println("error initializing fs: ", err)
+		return
+	}
+  // start init-wasm to mount filesystems.
+	err = fs.RunMount()
+	if err != nil {
+		fmt.Println("error in run auto-mount: ", err)
+		return
+	}
+
+  // ...
+
+  // deinitializing before quit.
+  err = fs.DeInit()
+  if err != nil {
+    fmt.Println("error deinitializing fs: ", err)
+  }
+}
+```
+
+在上述示例代码中,App名称为test,
+openNGVFS相关的根目录为`/home/satori/openngvfs_test_root`,
+那么我们应该像这样准备根目录的内容:
+
+```bash
+cd /home/satori/openngvfs_test_root
+mkdir -p ./syscfg/openngvfs/wasm
+```
+
+然后将init-wasm文件test-init.wasm放入
+`/home/satori/openngvfs_test_root/syscfg/openngvfs/wasm`
+目录中。
+
+接下来在`/home/satori/openngvfs_test_root/syscfg/openngvfs/`下创建配置文件
+`fstab.toml`并写入如下内容
+
+```toml
+[wasm]
+# 用于未单独定义的app的默认值
+default = "default-init"
+
+# 定义app `test` 的设置
+[test.app]
+wpms = "test-init"
+
+# 在这里定义全局的ExKV,这些键值可以在wasm中获取到
+[exkv.default]
+
+# 为每个app定义ExKV,会和全局ExKV合并,如key相同,则取每个app单独定义的值。
+[exkv.app.wpms]
+
+```
+
 = INIT WASI接口
 
 == WASM导出函数