vlang module 使用
  TEZNKK3IfmPf 2023年11月14日 21 0

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.
}

代码说明:
就是一个简单的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="https://www.ctyun.cn/portal/link.html?target=%2Fbundles%2Fblog-common.css%3Fv%3DKOZafwuaDasEedEenI5aTy8aXH0epbm6VUJ0v3vsT_Q1"/>
<link  type="text/css" rel="stylesheet" href="https://www.ctyun.cn/portal/link.html?target=%2Fskins%2FAnotherEon001%2Fbundle-AnotherEon001.css%3Fv%3DU5UoQIHpO_JKVLfS-_cGiJfvyStJK8n3Tl6p4K1f3ZI1"/>
<link  media="only screen and (max-width: 767px)" type="text/css" rel="stylesheet" href="https://www.ctyun.cn/portal/link.html?target=%2Fskins%2FAnotherEon001%2Fbundle-AnotherEon001-mobile.css%3Fv%3D08p1Qv0xTKiGzulu3Yk-n0vdvlMkpJByZdyNDoJhbTY1"/> 
  • 说明
    从官方文档我们可以看到实际上可以 v -lib /path 构建,但是很遗憾失败了,实际上如果类似gopath 的模式直接放到v path 是没有问题,同时v 目录是在首次运行自动帮助我们生成的
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月14日 0

暂无评论

推荐阅读
TEZNKK3IfmPf