小编vod*_*095的帖子

我可以在Heroku Hosting上为中国建立一个网站吗?

我有一个小nodeJS项目,我计划特别为来自中国的客户运行.我想使用http://heroku.com托管.

什么是最好的策略,不被大中国防火墙阻止,并实现与中国城市的正常通信速度.

firewall heroku node.js

5
推荐指数
1
解决办法
3983
查看次数

Golang - 无法解析JSON

我开始学习GO了,我遇到过这个问题.我有这个代码

package main

import (
  "fmt"
  "encoding/json"
//  "net/html"
)


func main(){
  type Weather struct {
    name string
    cod float64
    dt float64
    id float64
  }

  var rawWeather = []byte(`{"name":"London","cod":200,"dt":1407100800,"id":2643743}`)
  var w Weather
  err := json.Unmarshal(rawWeather, &w)
  if err != nil {
    fmt.Println("Some error", err)
  }
  fmt.Printf("%+v\n",w)
}
Run Code Online (Sandbox Code Playgroud)

当我运行它时,它显示了这一点

[nap@rhel projects]$ go run euler.go 
{name: cod:0 dt:0 id:0}
Run Code Online (Sandbox Code Playgroud)

因此,JSON不会被解析为weather结构.

任何想法,为什么会这样发生?

json go unmarshalling

2
推荐指数
1
解决办法
545
查看次数

Golang:使用像 node.js 这样的可读流从 PostgreSQL 数据库中选择几百万行

我有一个约 5000 万行的 PostgreSQL 表,我想编写 Go 代码来从这个表中选择约 100 万行,并以有效的方式处理它们。

上一次我使用 nodejs 和这个 NPM 模块pg-query-stream来生成可读记录流,所以我可以像处理任何可读对象流一样处理它们。

在这里,我发布了用于处理数据的简化代码:


const pg = require('pg');
const QueryStream = require('pg-query-stream');

 
//pipe 1,000,000 rows to stdout without blowing up your memory usage
pg.connect((err, client, done) => {
  if (err) throw err;
  const query = new QueryStream('SELECT * FROM generate_series(0, $1) num', [1000000]);
  const stream = client.query(query);
  //release the client when the stream is finished
  stream.on('end', done);
  stream.on('data', function(data) { 
    stream.pause();
    funcDoSomethingWithDataAsync(data, function(error) {
      if(error) throw error; …
Run Code Online (Sandbox Code Playgroud)

postgresql go node.js

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

标签 统计

go ×2

node.js ×2

firewall ×1

heroku ×1

json ×1

postgresql ×1

unmarshalling ×1