zoukankan      html  css  js  c++  java
  • vlang module 使用

    vlang 支持module,概念以及使用类似rust 以及golang 的gopath(从当前的文档以及使用来说),但是还不完整
    以及是够用,但是有问题

    v module 试用

    • 项目结构
     
    ├── modmain.v   // main 入口
    └── v
        ├── CHANGELOG.md
        ├── CONDUCT.md
        ├── CodeStructure.md
        ├── LICENSE
        ├── README.md
        ├── azure-pipelines.yml
        ├── base64
        ├── builtin
        ├── compiler
        ├── examples
        ├── fetchbaidu  // 我们开发的module
        ├── gg
        ├── gl
        ├── glfw
        ├── glm
        ├── gx
        ├── http
        ├── json
        ├── log
        ├── math
        ├── os
        ├── rand
        ├── stbi
        ├── sync
        ├── termcolor
        ├── tests
        ├── thirdparty
        └── time
    • 模块代码

      v/fetchbaidu/fetchbaidu.v

    module fetchbaidu
    import http
    // pub 暴露方法类似rust
    pub fn fetchindexpage() {
        resp := http.get('http://www.cnblogs.com/rongfengliang')
        println(resp)
    }

    代码说明:
    就是一个简单的http 数据请求,注意命名

    • main 入口

      modmain.v

     
    module main
    import fetchbaidu
    fn main() {
        fetchbaidu.fetchindexpage()
    }
     
     

    运行&& 测试

    • 运行
    v run modmain.v

    效果

    v run modmain.v     
    ============running modmain==============================
    <!DOCTYPE html>
    <html lang="zh-cn">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <meta name="referrer" content="origin" />
        <meta http-equiv="Cache-Control" content="no-transform" />
        <meta http-equiv="Cache-Control" content="no-siteapp" />
        <title>荣锋亮 - 博客园</title>
        <link type="text/css" rel="stylesheet" href="/bundles/blog-common.css?v=KOZafwuaDasEedEenI5aTy8aXH0epbm6VUJ0v3vsT_Q1"/>
    <link id="MainCss" type="text/css" rel="stylesheet" href="/skins/AnotherEon001/bundle-AnotherEon001.css?v=U5UoQIHpO_JKVLfS-_cGiJfvyStJK8n3Tl6p4K1f3ZI1"/>
    <link id="mobile-style" media="only screen and (max- 767px)" type="text/css" rel="stylesheet" href="/skins/AnotherEon001/bundle-AnotherEon001-mobile.css?v=08p1Qv0xTKiGzulu3Yk-n0vdvlMkpJByZdyNDoJhbTY1"/> 
    • 说明
      从官方文档我们可以看到实际上可以 v -lib /path 构建,但是很遗憾失败了,实际上如果类似gopath 的模式直接放到v path 是没有问题,同时v 目录是在首次运行自动帮助我们生成的

    参考资料

    https://vlang.io/docs#modules
    https://github.com/rongfengliang/vlang-learning

  • 相关阅读:
    关于学习netty的两个完整服务器客户端范例
    android-betterpickers
    ValueBar
    CircleDisplay
    JellyViewPager
    十天学习PHP之第二天
    android-測试so动态库(九)
    实习题
    android 编程小技巧(持续中)
    Codeforces Round #253 (Div. 2)——Borya and Hanabi
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/11102903.html
Copyright © 2011-2022 走看看