type T struct {
Id int
Name string
}
func Copy(a *T, b *T) error {
b.Id=5
b.Name="gert"
a = b
return nil
}
Run Code Online (Sandbox Code Playgroud)
a 仍然是空的,我必须这样做
func Copy(a *T, b *T) error {
b.Id = 5
b.Name = "gert"
a.Id = b.Id
a.Name = b.Name
return nil
}
Run Code Online (Sandbox Code Playgroud)
现在a是一样的b
为什么我怎么能复制*b到*a直接?
invalid indirect of oauth.RequestToken literal (type oauth.RequestToken)
为什么以下行无效?
func (s *Service) Callback(r *http.Request, req *RequestOauth, resp *Response) error {
c := endpoints.NewContext(r)
consumer.HttpClient=urlfetch.Client(c)
====>requestToken := *oauth.RequestToken{Token:req.Oauth_token, Secret:""}<======
b, err := TwitterApi(requestToken, req.Oauth_verifier)
resp.Message=b.Name
return err
}
func TwitterApi(requestToken *oauth.RequestToken, verificationCode string) (u *UserT, err error) {
accessToken, err := consumer.AuthorizeToken(requestToken, verificationCode)
if err != nil {log.Fatal(err)}
response, err := consumer.Get("https://api.twitter.com/1.1/account/verify_credentials.json", nil, accessToken)
if err != nil {log.Fatal(err)}
defer response.Body.Close()
b, err := ioutil.ReadAll(response.Body)
err = json.Unmarshal(b, &u)
return
}
Run Code Online (Sandbox Code Playgroud) 我不明白为什么kubernetes需要在只能包含一个pod模板的部署语句中使用pod选择器?随意教育我为什么kubernetes工程师在部署防御中引入选择器语句而不是从模板中自动选择pod?
---
apiVersion: v1
kind: Service
metadata:
name: grpc-service
spec:
type: LoadBalancer
ports:
- name: grpc
port: 8080
targetPort: 8080
protocol: TCP
selector:
app: grpc-test
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: grpc-deployment
spec:
replicas: 1
revisionHistoryLimit: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
selector:
matchLabels:
app: grpc-test
template:
metadata:
labels:
app: grpc-test
spec:
containers:
...
Run Code Online (Sandbox Code Playgroud)
为什么不简单地定义这样的东西?
---
apiVersion: v1
kind: Service
metadata:
name: grpc-service
spec:
type: LoadBalancer
ports:
- name: grpc
port: 8080
targetPort: 8080
protocol: TCP
selector:
app: …Run Code Online (Sandbox Code Playgroud) 如何在函数式编程语言中增加变量?
例如,我想这样做:
main :: IO ()
main = do
let i = 0
i = i + 1
print i
Run Code Online (Sandbox Code Playgroud)
预期产量:1.
在测试服务器上goapp serv它工作,在appengine本身它被application/octet-stream覆盖.
我如何告诉appengine停止这样做?
Could not guess mimetype for home/fonts/FontAwesome.otf. Using application/octet-stream...
我的配置文件:
application: test
version: 0
runtime: go
api_version: go1
threadsafe: true
handlers:
- url: /home
static_dir: home
- url: /home/font/(.*\.woff)
static_files: home/font/\1
upload: home/font/(.*\.woff)
http_headers:
Content-Type: application/font-woff
- url: /home/font/(.*\.svg)
static_files: home/font/\1
upload: home/font/(.*\.svg)
http_headers:
Content-Type: image/svg+xml
- url: /home/font/(.*\.eot)
static_files: home/font/\1
upload: home/font/(.*\.eot)
http_headers:
Content-Type: application/vnd.ms-fontobject
- url: /home/font/(.*\.ttf)
static_files: home/font/\1
upload: home/font/(.*\.ttf)
http_headers:
Content-Type: application/x-font-ttf
- url: /home/font/(.*\.otf)
static_files: home/font/\1
upload: home/font/(.*\.otf)
http_headers:
Content-Type: application/x-font-otf …Run Code Online (Sandbox Code Playgroud) 我在这个网站上找到了这个makefile .他们没有解释这个例子,所以我想知道是否有人新的发生了什么.
CC=g++
CFLAGS=-c -Wall
LDFLAGS=
SOURCES=main.cpp hello.cpp factorial.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=hello
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@
.cpp.o:
$(CC) $(CFLAGS) $< -o $@
Run Code Online (Sandbox Code Playgroud) app=function(req,res)
{
res.writeHead(200,{'Content-Type':'text/plain'})
var buffer=new Buffer(100)
var fs=require('fs')
fs.open('.'+req.url,'r',function(err,fd){
fs.fstat(fd,function(err, stats){
var i=0
var s=stats.size
console.log('.'+req.url+' '+s)
for(i=0;i<s;console.log(i)){
i=i+buffer.length
fs.read(fd,buffer,0,buffer.length,i,function(e,l,b){
res.write(b.toString('utf8',0,l))
console.log(b.toString('utf8',0,l))
})
}
res.end()
fs.close(fd)
})
})
}
http = require('http')
server = http.createServer(app)
server.listen(8000,"127.0.0.1")
console.log('GET http://127.0.0.1:8000/appwsgi/www/index.htm')
Run Code Online (Sandbox Code Playgroud)
为什么这只是从979字节文件多次显示最后100个字节?
为什么chrome浏览器没有显示任何输出?
gert@node:~/http$ node server.js
GET http://127.0.0.1:8000/appwsgi/www/index.htm
./appwsgi/www/index.htm 979
100
200
300
400
500
600
700
800
900
1000
"vi/vi.htm">vi</a> Edit online files on the server.
</div>
</body>
</html>
oad.<br/>
<a href=
"vi/vi.htm">vi</a> Edit online files on the server.
</div>
</body>
</html> …Run Code Online (Sandbox Code Playgroud) 当我使用chrome创建一个新的websocket时
new WebSocket('ws://gert:passwd@127.0.0.1:8001/dbname')
Run Code Online (Sandbox Code Playgroud)
nodejs服务器接收
GET /dbname HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Host: 127.0.0.1:8001
Origin: http://127.0.0.1:8000
Sec-WebSocket-Key1: ' 5 5) 4 1e a9 9 0 19
Sec-WebSocket-Key2: 3000909100 Q
Run Code Online (Sandbox Code Playgroud)
我怎样才能检索gert和passwd?
Couchdb只解析application/x-www-form-urlencoded.是否有设置enctype的FormData()属性?
xhr.open('put',document.myForm.action,false)
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
xhr.send(new FormData(document.myForm))
Run Code Online (Sandbox Code Playgroud) 该代码是否有效HTTP/1.1?
var fs = require('fs')
var http = require('http')
var buf=function(res,fd,i,s,buffer){
if(i+buffer.length<s){
fs.read(fd,buffer,0,buffer.length,i,function(e,l,b){
res.write(b.slice(0,l))
//console.log(b.toString('utf8',0,l))
i=i+buffer.length
buf(res,fd,i,s,buffer)
})
}
else{
fs.read(fd,buffer,0,buffer.length,i,function(e,l,b){
res.end(b.slice(0,l))
fs.close(fd)
})
}
}
var app = function(req,res){
var head={'Content-Type':'text/html; charset=UTF-8'}
switch(req.url.slice(-3)){
case '.js':head={'Content-Type':'text/javascript'};break;
case 'css':head={'Content-Type':'text/css'};break;
case 'png':head={'Content-Type':'image/png'};break;
case 'ico':head={'Content-Type':'image/x-icon'};break;
case 'ogg':head={'Content-Type':'audio/ogg'};break;
case 'ebm':head={'Content-Type':'video/webm'};break;
}
head['Transfer-Encoding']='chunked'
res.writeHead(200,head)
fs.open('.'+req.url,'r',function(err,fd){
fs.fstat(fd,function(err, stats){
console.log('.'+req.url+' '+stats.size+' '+head['Content-Type']+' '+head['Transfer-Encoding'])
var buffer = new Buffer(100)
buf(res,fd,0,stats.size,buffer)
})
})
}
http.createServer(app).listen(8000,"127.0.0.1")
console.log('GET http://127.0.0.1:8000/appwsgi/www/index.htm')
Run Code Online (Sandbox Code Playgroud)
我想我在这里违反了HTTP/1.1?文本文件确实可以正常工作,但这可能是巧合.我的标题是"200 OK"还是需要它为"100"?一个标题是否足够?