Both of them could write down nothing, however, there is still a effieciency difference. Look at the bench:
package base
import (
"io"
"os"
"testing"
Due to the method of `UnimplementedUserServiceServer` interface isn't exported, we need to run | |
the shell here to manipulate the generated file again: | |
```shell | |
sed -i '' '/type MockUserServiceServer struct {/,/}/ { | |
/type MockUserServiceServer struct {/!b | |
a\ | |
\tholepb.UnimplementedUserServiceServer | |
}' proto/mockedpb/api_grpc.pb.go | |
``` |
package main | |
import ( | |
"bytes" | |
"fmt" | |
"github.com/mitchellh/go-ps" | |
"io" | |
"os" | |
) |
In the following code snippet, return/pure
cannot work as it constructs StateT s IO (IO ())
, not StateT s IO ()
.
return/pure
will construct the value based on the currect monad in context, which is StateT s IO
. lift
will upgrade the
current monad(IO
) to the new monad through the transformer.
printState :: Show s => StateT s IO ()
printState = do
state <- get
When learning the haskell monad transformer(would call it monadt in the left content), a problem in my mind is why monadT
?
Because from a simple example view, we could make a pale of monad together to do what we want we want to do.
Technially, it's correct, the monadT is just a wrapper. For example, those two cases are equal.
ioOp :: IO String
ioOp = getLine
maybeOp :: Maybe String -> Maybe String
{-# LANGUAGE BlockArguments #-} | |
import System.Process | |
import Data.Text.IO (hGetLine) | |
import GHC.IO.Handle (isEOF, hGetLine) | |
import GHC.IO.Handle.Types (Handle) | |
import Data.Type.Equality (outer) | |
main :: IO () | |
main = do | |
(_, out , _, _) <- createProcess (proc "ls" []){ std_out = CreatePipe } |
func DownloadLicense(ctx *gin.Context) {
content:="Download file here happliy"
fileName := "hello.txt"
ctx.Header("Content-Disposition", "attachment; filename="+fileName)
ctx.Header("Content-Type", "application/text/plain")
ctx.Header("Accept-Length", fmt.Sprintf("%d", len(content)))
ctx.Writer.Write([]byte(content))
ctx.JSON(http.StatusOK, gin.H{
在过去处理跨域问题上,只要在nginx中加入如下内容,就可以解决跨域的问题:
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
那么根据上篇文章,使用一个OPTIONS
的方法就可以获取到一些跨域的内容,
然后浏览器经过预处理之后,就可以完成跨域的操作。这个经过实践应该来说是没有问题的,但写这个贴子希望可以稍微深入一点了解这个请求的内容是如何被nginx加上去的。
之前的跨域问题很意外,hmm,我对这个东西还没有什么概念。情况是这样的,首先我写了几个api,然后监听8080端口。使用nginx进行代理,将对80访问的内容和对432访问的内容全部转发到127.0.0.1:8080
去。然后前端在发请求的时候就遇到了跨域的问题。
解决方案:在nginx里面加一个同意跨域的设置 Access-Control-Allow-Origin:*
。即可解决。
回答 阻塞由浏览器来完成,即正常发送请求,后端正常给予响应,但响应结果被浏览器拦截。