小编Li *_*yao的帖子

如何禁用 TypeScript Object.defineProperty(exports, "__esModule", { value: true })?

ts 编译器在每个文件中发出这一行:

Object.defineProperty(exports, "__esModule", { value: true });
Run Code Online (Sandbox Code Playgroud)

但是我的代码在 Nodejs 上运行,我没有编写 libaray,所以我认为这行代码对我来说是不必要的。我怎样才能禁用它?我的编译器选项是:

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "allowJs": true,
        "sourceMap": true,
        "outDir": "build",
        "moduleResolution": "Node",
        "lib": ["es6"]
    }
}
Run Code Online (Sandbox Code Playgroud)

例如,编译这个 ts 文件:

function add(a: number, b: number): number {
    return a + b
}

export { add }
Run Code Online (Sandbox Code Playgroud)

我有:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function add(a, b) {
    return a + b;
}
exports.add = add;
//# sourceMappingURL=App.js.map
Run Code Online (Sandbox Code Playgroud)

如何删除第二行?

node.js typescript ecmascript-6

6
推荐指数
1
解决办法
1766
查看次数

Node.js 6.10.2加密AES无效的密钥长度

我尝试使用加密来加密文件。这是我的代码:

const crypto = require('crypto');
const fs = require('fs');

const input = fs.createReadStream('test.jpg');
const output = fs.createWriteStream('test.enc');

const sharedSecret = crypto.randomBytes(256);
const initializationVector = crypto.randomBytes(16);

const cipher = crypto.createCipheriv('aes-256-cbc', sharedSecret, initializationVector);

input.pipe(cipher).pipe(output);
Run Code Online (Sandbox Code Playgroud)

我得到了错误:

crypto.js:191
  this._handle.initiv(cipher, toBuf(key), toBuf(iv));
               ^

Error: Invalid key length
    at Error (native)
    at new Cipheriv (crypto.js:191:16)
    at Object.Cipheriv (crypto.js:189:12)
    at Object.<anonymous> (/Users/lijinyao/Projects/HyperAlbum/Encryption/encrypt.js:10:23)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
Run Code Online (Sandbox Code Playgroud)

我虽然sharedSecret的长度应与aes-length相同,但事实并非如此。我应该使用多长?谢谢 :)

encryption node.js

4
推荐指数
1
解决办法
4257
查看次数

如何在 Go-Gorm 中禁用默认错误记录器

我在 MySQL 中使用 GORM,我遇到并处理了错误Error 1062: Duplicate entry。问题是它仍然打印到控制台。

代码gym/models/auth.go:49

func AddAuth(username, password string) error {
    passwordHash, err := auth.HashPassword(password, argon2Conf)
    if err != nil {
        return err
    }
    userAuth := Auth{
        Username: username,
        Password: passwordHash,
    }
    return db.Create(&userAuth).Error
}
Run Code Online (Sandbox Code Playgroud)

我正在处理处理程序函数中的错误:

func SignUpHandler(c *gin.Context) {
    var form user
    if err := c.ShouldBind(&form); err != nil {
        c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
        return
    }
    if err := models.AddAuth(form.Username, form.Password); err == nil {
        c.JSON(http.StatusOK, gin.H{"status": "you are signed in"})
    } else …
Run Code Online (Sandbox Code Playgroud)

mysql error-handling go go-gorm

4
推荐指数
1
解决办法
3233
查看次数

go 的 map 哈希函数如何工作,具有“相同”值的不同类型会导致不同的键?

我知道这个值是不相同的,所以我双qouted它,我想知道的是Go的地图散列是如何工作的,这样cusKeya在类型的结果不同的关键是不同的。

package main

import (
    "fmt"
)

type key int

const cusKey key = 1
const a int = 1


func main() {
    dic := make(map[interface{}]interface{})
    dic[cusKey] = 5
    dic[a] = 6
    fmt.Println(dic[cusKey])
    fmt.Println(dic[a])
}

Run Code Online (Sandbox Code Playgroud)

输出是

5
6
Run Code Online (Sandbox Code Playgroud)

如何实现这一目标?这两个键值都是1.

我知道如果类型不同,则两个值不同。所以两者1并不相同。

但实际上 go 的地图是如何做到的呢?我试图map.go在源代码中找到,但我找不到在哪里实现哈希函数。它是否使用类型注释计算键的哈希?

dictionary hashmap go

4
推荐指数
2
解决办法
93
查看次数

如何使用route命令配置默认ipv6路由

我的系统是 macOS,我尝试使用/sbin/route配置一些自定义路由,我知道0.0.0.0是默认的 ipv4 路由,因此我可以通过运行来删除/更改/添加默认的 ipv4 路由route delete 0.0.0.0

然后搜了wiki发现ipv6的默认路由地址是::or ,我尝试运行or::/0删除路由,结果返回。route delete ::route delete ::/0route: bad address: ::

我的ipv6路由表是:

Internet6:
Destination                             Gateway                         Flags         Netif Expire
default                                 fe80::3600:a3ff:fed3:93e5%en0   UGcI            en0
default                                 fe80::%utun0                    UGcI          utun0
::1                                     ::1                             UHL             lo0
Run Code Online (Sandbox Code Playgroud)

问题是该default值是什么以及如何更改它?

macos networking bsd routes ipv6

-1
推荐指数
1
解决办法
6632
查看次数