所以我有这个Go http处理程序,它将一些POST内容存储到数据存储区中,并检索一些其他信息作为响应.在后端我使用:
func handleMessageQueue(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
if r.Method == "POST" {
c := appengine.NewContext(r)
body, _ := ioutil.ReadAll(r.Body)
auth := string(body[:])
r.Body.Close()
q := datastore.NewQuery("Message").Order("-Date")
var msg []Message
key, err := q.GetAll(c, &msg)
if err != nil {
c.Errorf("fetching msg: %v", err)
return
}
w.Header().Set("Content-Type", "application/json")
jsonMsg, err := json.Marshal(msg)
msgstr := string(jsonMsg)
fmt.Fprint(w, msgstr)
return
}
}
Run Code Online (Sandbox Code Playgroud)
在我的firefox OS应用程序中,我使用:
var message = "content";
request = new XMLHttpRequest();
request.open('POST', 'http://localhost:8080/msgs', true);
request.onload = function () { …Run Code Online (Sandbox Code Playgroud) 在webpack 1.x中,我可以使用webpack配置中的eslint属性来启用自动修复我的linting错误:
...
module.exports = {
devtool: 'source-map',
entry: './src/app.js',
eslint: {
configFile: '.eslintrc',
fix: true
},
...
Run Code Online (Sandbox Code Playgroud)
但是,在webpack 2.x中,因此我无法使用自动修复功能,因为我不知道在我的webpack配置中将它设置在何处.在我的webpack中使用eslint属性configFile抛出一个WebpackOptionsValidationError.
我正在制作这个简单的网络服务器,可以托管我的博客,但无论我做什么; 我无法在我的html /模板中执行正确的格式化时间.
这是我做的:
我创建了这个结构:
type Blogpost struct {
Title string
Content string
Date time.Time
}
Run Code Online (Sandbox Code Playgroud)
接下来我创建了这个小函数,它从Appengine数据存储区中检索具有相应标题/日期的博客帖子并将其作为切片返回:
func GetBlogs(r *http.Request, max int) []Blogpost {
c := appengine.NewContext(r)
q := datastore.NewQuery("Blogpost").Order("-Date").Limit(max)
bp := make([]Blogpost, 0, max)
q.GetAll(c, &bp)
return bp
}
Run Code Online (Sandbox Code Playgroud)
最后,在blogHandler中,我使用以下方法根据从Appengine数据存储中检索到的数据创建一个切片:
blogs := GetBlogs(r, 10)
Run Code Online (Sandbox Code Playgroud)
现在当我执行这样名为博客的模板时,博客的日期将被解析为默认日期:
blog.Execute(w, blogs) // gives dates like: 2013-09-03 16:06:48 +0000 UTC
Run Code Online (Sandbox Code Playgroud)
所以,我,作为我的Golang n00b,会说像下面这样的函数会给我我想要的结果
blogs[0].Date = blogs[0].Date.Format("02-01-2006 15:04:05") // Would return like 03-09-2013 16:06:48, at least when you print the formatted date that is.
Run Code Online (Sandbox Code Playgroud)
然而,这会导致类型冲突,我尝试使用以下方法解决:
blogs[0].Date, …Run Code Online (Sandbox Code Playgroud) 我正在使用golang的"html/template"包来使用相同的_base.html作为框架在多个页面上提供内容.我将多个html文件(_base.html和内容文件)合并为一个.
func main() {
http.HandleFunc("/", indexHandler)
http.HandleFunc("/blog/", blogHandler)
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("http/css"))))
http.ListenAndServe(":1337", nil)
}
func indexHandler(w http.ResponseWriter, r *http.Request) {
index := template.Must(template.ParseFiles(
"http/html/_base.html",
"http/html/index.html",
))
index.Execute(w, nil)
}
func blogHandler(w http.ResponseWriter, r *http.Request) {
blog := template.Must(template.ParseFiles(
"http/html/_base.html",
"http/html/blog.html",
))
blog.Execute(w, nil)
}
Run Code Online (Sandbox Code Playgroud)
在我的网络服务器的根目录上这样做我的css渲染得很好,因为_base.html中我的.css的html链接标记使用以下命令指向正确的目录:
<link href="css/style.css" rel="stylesheet">
Run Code Online (Sandbox Code Playgroud)
然而,当我从/ to/blog /导航时,我的css降低了一级(或者我升级了,但是你想看到它)所以css href突然指向/blog/css/style.css并且因此它不会呈现.
这可以很容易地修复,说明我与_base.html合并的每个内容文件中的css级别,但是我觉得必须有另一种更清洁,不同的方式.在这种情况下,我的直觉是否存在误导?
我正在使用MapBox GL JS来创建带有自定义标记的地图:
var marker = new mapboxgl.Marker(container)
.setLngLat([
datacenters[country][city].coordinates.lng,
datacenters[country][city].coordinates.lat
])
.addTo(map);
Run Code Online (Sandbox Code Playgroud)
但是,我似乎对标记有某种偏移问题.问题是:当缩小一点时,标记的底部并没有真正指向确切的位置:
当我进一步放大它到达目的地时,它指向确切的位置.
我真的很喜欢MapBox GL,但这个特殊的问题让我烦恼,我很想知道如何解决它.当这个问题得到解决时,我的实现远比我使用的原始映射软件更优越.
我用babel-eslint来修饰/修复我的代码.伟大的工作,直到我想采取一些ES2017 async await发现overhere.
我相应地改变了我的React应用程序,尽管有些不同:
我的index.js的相关部分:
async function renderApp() {
const store = await configureStore()
const history = syncHistoryWithStore(browserHistory, store, {
selectLocationState: state => state.get('routing')
})
ReactDOM.render(
<AppContainer>
<MuiThemeProvider muiTheme={muiTheme}>
<Provider store={store}>
<Router history={history} routes={routes(store)} />
</Provider>
</MuiThemeProvider>
</AppContainer>,
document.getElementById('root')
)
}
renderApp()
Run Code Online (Sandbox Code Playgroud)
我的商店:
// @flow
import 'babel-polyfill'
import { addFormSubmitSagaTo } from 'redux-form-submit-saga/es/immutable'
import { applyMiddleware, createStore, compose } from 'redux'
import { autoRehydrate, persistStore } from 'redux-persist-immutable'
import { browserHistory } from 'react-router'
import { combineReducers …Run Code Online (Sandbox Code Playgroud) 我最近从MySQL切换到postgres作为node.js项目的数据库.虽然我能够从我的本地pgAdmin III(OSX)客户端访问我的远程postgres数据库,但到目前为止我一直无法通过node.js连接到我的数据库.我确信我为pgAdmin和我的node.js输入的凭据完全相同.我尝试过的另一件事是在我的数据库服务器的pg_hba.conf中设置我的本地ipadress而不是md5.有什么我做错了吗?我最喜欢的搜索引擎提出了一些关于重置我的本地操作系统的令人担忧的命中.我刚刚使用了node-postgres的github repo doc中的示例:
var pg = require('pg');
var conString = "postgres://myusername:mypassword@hostname:5432/dbname";
var client = new pg.Client(conString);
client.connect(function(err) {
if(err) {
return console.error('could not connect to postgres', err);
}
client.query('SELECT NOW() AS "theTime"', function(err, result) {
if(err) {
return console.error('error running query', err);
}
console.log(result.rows[0].theTime);
client.end();
});
});
Run Code Online (Sandbox Code Playgroud)
这些是我每次尝试启动服务器时遇到的错误:
could not connect to postgres { [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
Run Code Online (Sandbox Code Playgroud)
非常感谢帮助
当我的gulp在我的sass文件上运行罗盘时,我遇到以下错误:
error src/scss/site/style.scss (/Library/Ruby/Gems/2.0.0/gems/sass-3.4.6/lib/sass/selector/abstract_sequence.rb:96:in `block in _specificity': undefined method `specificity' for [:not(.pointer)]:Array)
Run Code Online (Sandbox Code Playgroud)
我不知道这个错误究竟意味着什么,但它所指向的文件没有特殊的来源,它只是一个小的合法scss文件:
@import '../general';
.tld {
color: $color-primary;
}
Run Code Online (Sandbox Code Playgroud)
我也一直在我的Gulp流中得到这些错误,它可能是相关的:
[21:45:01] Ignoring psych-2.0.6 because its extensions are not built. Try: gem pristine psych-2.0.6
[21:45:01] Ignoring ffi-1.9.5 because its extensions are not built. Try: gem pristine ffi-1.9.5
Run Code Online (Sandbox Code Playgroud)
当然,我尝试了"宝石原始",但这没有做任何事情.
我不知道发生了什么事,我知道我的gulpfile上周是一样的,它完美无缺.我安装了OSX约塞米蒂并没有做任何特别的事情.
我知道我的描述缺乏东西,但那是因为我不知道在哪里寻找解决方案,因为我不理解错误.
我的 pyenv 工作正常,但它似乎没有运行位于以下位置的激活脚本/usr/local/var/pyenv/versions/project/bin/activate.fish
激活我的环境时,它会提供以下输出,但它不会回显激活脚本中的任何内容,这表明它没有运行。
dani@localhost ~/d/project> pyenv activate project
pyenv-virtualenv: prompt changing not working for fish.
Run Code Online (Sandbox Code Playgroud)
当然,我可以source手动更改该文件,但我太想找出它没有运行的原因。有某种调试模式吗?我不知道如何接近。
我使用postgres数据库查询来确定我的下一个操作.我需要等待结果才能执行下一行代码.现在我conn.query返回一个Future,但是当我将代码放在另一个函数中时,我无法将其设置为异步.
main() {
// get the database connection string from the settings.ini in the project root folder
db = getdb();
geturl().then((String url) => print(url));
}
Future geturl() {
connect(db).then((conn) {
conn.query("select trim(url) from crawler.crawls where content IS NULL").toList()
.then((result) { return result[0].toString(); })
.catchError((err) => print('Query error: $err'))
.whenComplete(() {
conn.close();
});
});
}
Run Code Online (Sandbox Code Playgroud)
我只是想geturl()等待返回的值,但无论我做什么; 它会立即发射.任何人都能指出我的一篇文档解释了我在这里缺少的东西吗?
go ×3
eslint ×2
ajax ×1
async-await ×1
babel ×1
compass ×1
cors ×1
css ×1
dart ×1
dart-async ×1
firefox-os ×1
fish ×1
gulp ×1
gulp-sass ×1
html ×1
javascript ×1
mapbox ×1
mapbox-gl ×1
mapbox-gl-js ×1
node.js ×1
osx-yosemite ×1
postgresql ×1
pyenv ×1
virtualenv ×1
webpack ×1
webpack-2 ×1