• 【soar-w5学习和使用】


    一.docker部署

    1.下载w5代码,地址https://github.com/w5teams/w5
    2.进入w5目录下面,执行

    cp -r apps docker && cp config.ini docker && docker-compose up -d
    
    • 1

    3.初始化成功
    访问地址:http://ip:8888/ 账号:admin 密码:12345678

    二.app开发

    app整体概括

    ├── helloworld       # APP 目录名
    │   ├── app.json    # APP 配置文件
    │   ├── icon.png    # APP 图标
    │   ├── main       # APP 代码
    |   |   └── run.py  # APP 入口文件
    │   └── readme.md   # APP 说明文件
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    1.配置文件

    • app.json配置文件https://w5.io/help/dev/dev2.html

    • 需要注意函数名字需要一致,参数顺序一致,当修改完函数不成效时,注意强制刷新或者重启w5

    • app配置文件,action里面放相应动作绑定的函数,可以多个动作,每个动作对应一个函数

    {
      "identification": "w5soar",               // w5soar 签名,无需更改,必须存在
      "is_public": true,                        // 是否为公开 APP,设置 false 为私有 APP
      "name": "Hello World",                     // APP 名称
      "version": "0.1",                         // APP 版本
      "description": "W5 SOAR - Hello World",    // APP 描述
      "type": "基本应用",                        // APP 分类
      "action": [                               // APP 动作列表
        {
          "name": "HelloWorld",                  // APP 动作名称
          "func": "hello_world"                  // 动作对应的函数名
        },
        {
          "name": "test",                      // APP 动作名称
          "func": "app_test"                   // 动作对应的函数名
        }
      ],
      "args": {                                 // 动作参数
        "hello_world": [                         // 动作对应的函数名
          {
            "key": "name",                      // 动作参数名
            "type": "text",                     // 动作参数类型
            "required": true                    // 是否是必填项
          }
        ],
        "app_test": [                           // 动作对应的函数名
          {
            "key": "name",                      // 动作参数名
            "type": "text",                     // 动作参数类型
            "required": true                    // 是否是必填项
          },
          {
            "key": "sex",                       // 动作参数名
            "type": "text",                     // 动作参数类型
            "required": true                    // 是否是必填项
          }
        ],
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39

    参数支持5种类型

    类型      说明
    text    文本输入框
    password        密码输入框
    textarea        多行文本输入框
    number  数字输入框
    select  下拉选择框
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    参数支持默认,是否必填

    "args": {                                 // 动作参数
        "app_demo": [                           // 动作对应的函数名
          {
            "key": "name",                      // 动作参数名
            "type": "text",                     // 动作参数类型
            "default": "W5",                    // 参数默认值,不写默认为空
            "required": true                    // 是否是必填项
          },
          {
            "key": "age",                       // 动作参数名
            "type": "number",                   // 动作参数类型
            "default": 18,                      // 参数默认值,不写默认为空
            "required": true                    // 是否是必填项
          },
          {
            "key": "desc",                      // 动作参数名
            "type": "textarea",                 // 动作参数类型
            "required": true                    // 是否是必填项
          },
          {
            "key": "type",                      // 动作参数名
            "type": "select",                   // 动作参数类型
            "default": "test",                  // 参数默认值,不写默认不选择
            "data": [                           // 下拉列表
              "test",
              "test2",
              "test3",
              "test4"
            ],
            "required": true                    // 是否是必填项
          }
        ]
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33

    2.app图标
    图标名称 icon.png 不可改变
    图标大小 200 x 200

    3.app代码run.py

    • run.py主要写函数逻辑,注意传入参数必须和配置文件里面的参数一致
    #!/usr/bin/env python
     encoding:utf-8
    import json
    from loguru import logger
    
    async def hello_world(name):
        logger.info("[Hello World] APP 执行参数为: {name}", name=name)
        try:
            a = json.loads(name)
        except Exception as e:
            a = name
        return {"status": 0, "result":a }
    
    async def app_test(name,sex):
        logger.info("[Hello World] APP 执行参数为: {name},{sex}", name=name,sex=sex)
    
        return {"status": 0, "result":name+sex}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    4.readme.md说明文件
    按照参数和类型写就好

    5.w5的开发规范请看https://w5.io/help/dev/dev5.html

    三.使用app

    • 每个app都会有个uuid
    • 不同的动作对应配置文件设置的函数
    • result是获取每个app结果的参数

    1. 获取上一个app的结果@(对应app的uuid.result)
    在这里插入图片描述
    2. 获取上一个app的参数结果@(对应app的参数字段名.result)
    在这里插入图片描述

    3.获取app结果是json数据,json数据里面某个键的内容@(对应app的uuid.result!>键字段)
    在这里插入图片描述
    一些其他json的使用方法https://w5.io/help/use/use7.html

    四.for 的使用

    for介绍https://w5.io/help/use/use9.html

    1.类型可选字典,数组,次数
    循环数据放需要循环的内容,注意格式需要和类型一致

    在这里插入图片描述
    2.下个app使用方法
    数组变量:@(uuid.value)
    字典变量:@(uuid.key) @(uuid.value)
    数字变量:@(uuid.value)

    五.if 的使用

    if的介绍https://w5.io/help/use/use2.html
    没学会,有学会的可以教教我

  • 相关阅读:
    Linux内存泄露案例分析和内存管理分享
    从0开始学习JavaScript--深入理解JavaScript的async/await
    在docker中运行mysql容器
    AgileConfig-1.7.0 发布,支持 SSO
    PTA 7-2 彩虹瓶(单调栈)
    Win11怎么连接宽带?
    C语言嵌入式系统编程注意事项之内存操作
    WPF实现拖动控件功能(类似从工具箱拖出工具)
    想要糖尿病逆转,健康饮食必不可少
    微服务架构详解
  • 原文地址:https://blog.csdn.net/zhuziwan/article/details/133176068