我有问题
不允许进口周期
看来,当我试图测试我的控制器时.作为输出我有
can't load package: import cycle not allowed
package project/controllers/account
imports project/controllers/base
imports project/components/mux
imports project/controllers/account
import cycle not allowed
package project/controllers/account
imports project/controllers/base
imports project/components/mux
imports project/controllers/account
import cycle not allowed
package project/controllers/account
imports project/controllers/base
imports project/components/mux
imports project/controllers/routes
imports project/controllers/base
Run Code Online (Sandbox Code Playgroud)
有人能告诉我,如何阅读或理解这个错误?依赖在哪里错了?
我已经从Monoid Morphisms,Products和Coproducts中阅读了有关Monoid同态的知识,并且无法理解100%。
作者说(强调原文):
该
length
函数从映射到String
,Int
同时保留类半体结构。这种以一种保存方式从一个单半体映射到另一个单半体的函数称为单半体同态。通常,对于monoidM
和N
,是同态f: M => N
,以及所有值x:M
,y:M
以下等式成立:Run Code Online (Sandbox Code Playgroud)f(x |+| y) == (f(x) |+| f(y)) f(mzero[M]) == mzero[N]
他的意思是说,由于数据类型String
和Int
是monoid ,并且函数length
映射String => Int
保留了monoid结构(Int
是monoid),所以称为monoid同态,对吗?
haskell functional-programming scala category-theory monoids
我试图将一个新元素添加到列表中,如下所示:
iex(8)> l = [3,5,7,7,8] ++ 3
[3, 5, 7, 7, 8 | 3]
iex(9)> l
[3, 5, 7, 7, 8 | 3]
Run Code Online (Sandbox Code Playgroud)
为什么我会像第五名一样获得第五名
8 | 3
Run Code Online (Sandbox Code Playgroud)
它的意思是什么?
如何在列表中添加新元素?
-------- 更新 --------
我尝试循环列表如下:
iex(2)> l = [1,2] ++ 3
[1, 2 | 3]
iex(3)> Enum.each(l, fn(x) -> IO.puts(x) end)
1
2
** (FunctionClauseError) no function clause matching in Enum."-each/2-lists^foreach/1-0-"/2
(elixir) lib/enum.ex:604: Enum."-each/2-lists^foreach/1-0-"(#Function<6.54118792/1 in :erl_eval.expr/5>, 3)
(elixir) lib/enum.ex:604: Enum.each/2
Run Code Online (Sandbox Code Playgroud)
由于数字2的指针不是指向列表而是指向值3,我如何循环列表?
我创建了一个基于.NET 4.6.2版本的库.
在库中,我添加了EntityFramework版本6.1.3包.
我创建了一个模型如下
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Components.Models
{
public class Session
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public string Id { get; set; }
[Key]
[Required]
public string Identity { get; set; }
[Required]
public DateTime CreatedAt { get; set; }
[Required]
public DateTime UpdatedAt { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
和dbcontext
using System.Configuration;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using Components.Models;
namespace Components.DataContexts
{
public class SessionContext : DbContext
{
public SessionContext() : base(ConfigurationManager.ConnectionStrings["sessiondb"].ConnectionString)
{
}
public DbSet<Session> Sessions { …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的身份验证系统中实现JWT,我有几个问题.要存储令牌,我可以使用cookie,但也可以使用localStorage
或sessionStorage
.
哪个是最好的选择?
我已经读过JWT保护网站免受CSRF的侵害.但是,我无法想象假设我将JWT令牌保存在cookie存储中会如何工作.
那么它将如何保护CSRF?
更新1
我看到了一些使用示例,如下所示:
curl -v -X POST -H "Authorization: Basic VE01enNFem9FZG9NRERjVEJjbXRBcWJGdTBFYTpYUU9URExINlBBOHJvUHJfSktrTHhUSTNseGNh"
Run Code Online (Sandbox Code Playgroud)
当我从浏览器向服务器发出请求时,如何实现?我还看到有些人在URL中实现了令牌:
http://exmple.com?jwt=token
Run Code Online (Sandbox Code Playgroud)
如果我通过AJAX发出请求,那么我可以设置一个标题jwt: [token]
,然后我可以从标题中读取标记.
更新2
我安装了高级REST客户端谷歌浏览器扩展,并能够将令牌作为自定义标头传递.在向服务器发出GET请求时,是否可以通过Javascript设置此标头数据?
我尝试在节点中使用测试工具mocha.请考虑以下测试方案
var requirejs = require('requirejs');
requirejs.config({
//Pass the top-level main.js/index.js require
//function to requirejs so that node modules
//are loaded relative to the top-level JS file.
nodeRequire: require
});
describe('Testing controller', function () {
it('Should be pass', function (done) {
(4).should.equal(4);
done();
});
it('Should avoid name king', function (done) {
requirejs(['../server/libs/validate_name'], function (validateName) {
var err_test, accountExists_test, notAllow_test, available_test;
validateName('anu', function (err, accountExists, notAllow, available) {
accountExists.should.not.be.true;
done();
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
作为测试结果我有:
$ make test
./node_modules/.bin/mocha \
--reporter list …
Run Code Online (Sandbox Code Playgroud) 我正在使用gorilla mux进行管理路由.我缺少的是在每个请求之间集成中间件.
例如
package main
import (
"fmt"
"github.com/gorilla/mux"
"log"
"net/http"
"strconv"
)
func HomeHandler(response http.ResponseWriter, request *http.Request) {
fmt.Fprintf(response, "Hello home")
}
func main() {
port := 3000
portstring := strconv.Itoa(port)
r := mux.NewRouter()
r.HandleFunc("/", HomeHandler)
http.Handle("/", r)
log.Print("Listening on port " + portstring + " ... ")
err := http.ListenAndServe(":"+portstring, nil)
if err != nil {
log.Fatal("ListenAndServe error: ", err)
}
}
Run Code Online (Sandbox Code Playgroud)
每个传入的请求都应该通过中间件.我怎样才能在这里整合中间件?
更新
我将它与大猩猩/会话结合使用,他们说:
重要说明:如果您不使用gorilla/mux,则需要使用context.ClearHandler包装处理程序,否则您将泄漏内存!一个简单的方法是在调用http.ListenAndServe时包装顶级多路复用器:
我该如何防止这种情况?
我有以下课程:
case class Box[+A](value: A) {
def set(a: A): Box[A] = Box(a)
}
Run Code Online (Sandbox Code Playgroud)
并且编译器抱怨:
Error:(4, 11) covariant type A occurs in contravariant position in type A of value a
def set(a: A): Box[A] = Box(a)
Run Code Online (Sandbox Code Playgroud)
我正在搜索关于错误的很多内容,但找不到有助于我理解错误的有用内容.
有人可以解释,为什么会发生错误?