.env 文件用于存储某个项目中的环境变量。我希望能够轻松地以编程方式修改 .env 文件,在这种情况下,据我所知,使用 JSON(.json 文件)会容易得多。
假设我有这样的文件 env.json:
{
"use_shell_version": true,
"verbosityLevel":3,
"color": "yellow"
}
Run Code Online (Sandbox Code Playgroud)
有没有好的方法可以导出这些?是否有一些 .env 文件格式可以轻松地由机器而不是手动修改?
使用Java,我们可以创建一个ActionListener类的实例,它有一个抽象方法,就像这样(它已经有一段时间了):
new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// whatever
}
}
Run Code Online (Sandbox Code Playgroud)
使用TypeScript,这是我能得到的最接近的:
export abstract class ActionListener {
constructor(f: any) {
this.actionPerformed = f;
}
abstract actionPerformed(input: string): string;
}
new ActionListener(input => {
});
Run Code Online (Sandbox Code Playgroud)
至少有两个问题:
如果你使用带有TS的抽象方法,那么类必须抽象(我认为使用Java你可以使用抽象方法,以后可以实现).
我不知道如何将输入函数f的类型绑定/绑定到解析方法的类型.
有谁知道有没有办法用TS做到这一点?
也许我们不能使用abstractTS,并且必须更像这样:
type ActionPerformed = (input: string) => string;
export class ActionListener {
parse: ActionPerformed;
constructor(f: ActionPerformed) {
this.parse = f;
}
}
new ActionListener(input => {
return 'foo';
});
Run Code Online (Sandbox Code Playgroud) 说我有这个:
A - B - C - E - F [integration]
\
G - H - I [feature]
Run Code Online (Sandbox Code Playgroud)
在 commit 之后I,我们通过集成进行变基:
git fetch origin
git rebase integration
Run Code Online (Sandbox Code Playgroud)
所以现在我们有:
A - B - C - E - F [integration]
\
B - C - E - F - G - H - I [feature]
Run Code Online (Sandbox Code Playgroud)
然后说我们将功能分支合并到集成中,然后我们有:
A - B - C - E - F - G - H - I [integration]
\
B - C - E - F …Run Code Online (Sandbox Code Playgroud) 使用 bash,我认为这是可能的,但不确定 JavaScript,假设我们有这个:
const {masterid} = req.query;
if (!masterid) {
return res.status(500).send(new Error('Missing query param "masterid".'));
}
Run Code Online (Sandbox Code Playgroud)
我想要做的不是在字符串中硬编码“masterid”,而是执行如下操作:
const {masterid} = req.query;
if (!masterid) {
return res.status(500).send(new Error(`Missing query param "${Reflect(masterid).name()}.".`));
}
Run Code Online (Sandbox Code Playgroud)
有没有办法使用 Reflect API 来做到这一点?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect
这让我在学习 Go 的最后一个月感到困惑:
func Auth(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { // hmmmm
// ...
next.ServeHTTP(w, r)
}
}
Run Code Online (Sandbox Code Playgroud)
在这里我们可以看到 Auth 函数返回 type http.HandlerFunc。该类型只是一个函数。那么当您调用 时next.ServeHTTP,该方法是在何时/何处定义的?
我有这个:
public class Models {
public static class User extends BaseModel {
public static {
public final TableField ID = new TableField("user_id", "userId");
public final TableField HANDLE = new TableField("user_handle", "userHandle");
public final TableField EMAIL = new TableField("user_email", "userEmail");
}
}
}
Run Code Online (Sandbox Code Playgroud)
java 说 public 不允许在“public static {}”块中的 static 之前或 final 之前作为修饰符。有谁知道为什么?也许我不明白静态块与将所有 3 个字段声明为public final static.
这是我看到的:
和这个
如果我有这个:
console.log('12345'.slice(-3)); // I get '345'
Run Code Online (Sandbox Code Playgroud)
但当我这样做时:
console.log('12345'.slice(-3, 0)); // I get '' (empty string).
Run Code Online (Sandbox Code Playgroud)
这背后的原因是什么?对我来说完全是无稽之谈。有没有一个 JS API 可以像我在这里期望的那样包裹字符串?(我又期待“345”。)
我有这个代码:
s := grpc.NewServer()
pb.RegisterMessageServiceServer(s, &messageServer{})
Run Code Online (Sandbox Code Playgroud)
我有这个错误:
无法使用“&messageServer{}”(类型 *messageServer)作为类型 MessageServiceServer 类型无法实现“MessageServiceServer”,因为它具有非导出方法并且是在不同的包中定义的
我的 messageServer 结构如下所示:
type messageServer struct{}
func (s *messageServer) mustEmbedUnimplementedMessageServiceServer() {
//TODO implement me
panic("implement me")
}
func (s *messageServer) MustEmbedUnimplementedMessageServiceServer() {
//TODO implement me
panic("implement me")
}
func (s *messageServer) SendMessage(ctx context.Context, msg *pb.Message) (*pb.Response, error) {
// Write the message to Kafka
producer, err := sarama.NewSyncProducer([]string{kafkaBroker}, nil)
if err != nil {
log.Fatalf("Error creating Kafka producer: %v", err)
return nil, err
}
defer producer.Close()
kafkaMsg := &sarama.ProducerMessage{ …Run Code Online (Sandbox Code Playgroud) 给定动态网址列表,我无法从YouTube加载一些iframe视频。
我有这个HTML:
<div fxLayout="column">
<div *ngFor="let v of videos">
<div fxLayout="row">
<div>
Type: {{v.type}}
</div>
<div>
<iframe width="420" height="315"
[src]="getVideoURL(v)">
</iframe>
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的Angular代码:
import { Component, OnInit } from '@angular/core';
import {DomSanitizer} from '@angular/platform-browser';
@Component({
templateUrl: './docs.component.html',
styleUrls: ['./docs.component.scss']
})
export class DocsComponent implements OnInit {
videos = [
{type:'installation', val:'https://www.youtube.com/embed/tgbNymZ7vqY'},
{type:'usage', val: 'https://www.youtube.com/watch?v=ahla7JgpDEE'},
{type:'keyboard shortcuts',val:'https://www.youtube.com/watch?v=bVYXWVs0Prc'}
];
constructor(private sanitizer: DomSanitizer) {
}
ngOnInit() {
}
getVideoURL(v: any){
return this.sanitizer.bypassSecurityTrustUrl(v.val)
}
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
错误:需要一个安全的ResourceURL,并有一个URL
有人知道如何解决此错误吗?
我有这个:
methods := [...]string{"POST", "PUT"}
router.HandleFunc(h.makeRegisterNewUser("/api/v1/register", v)).Methods("POST", "PUT")
Run Code Online (Sandbox Code Playgroud)
除了methods未使用之外.如果我试试这个:
methods := [...]string{"POST", "PUT"}
router.HandleFunc(h.makeRegisterNewUser("/api/v1/register", v)).Methods(methods...)
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
不能在router.HandleFunc(h.makeRegisterNewUser("/ api/v1/register",v))的参数中使用方法(类型[2]字符串)作为类型[]字符串.
我无法想出这个
假设我有这两个列表(可能大小不同):
const a = [0,1,3];
const b = [7,2,6,4];
Run Code Online (Sandbox Code Playgroud)
假设我想将,的元素与的元素交换?最简单的方法是什么?1a3b
又名,我想这样做:
swap(1, a, 3, b) => { a: [0,4,3], b: [7,2,6,1] }
Run Code Online (Sandbox Code Playgroud) 这对谷歌来说很难,所以我想有人必须在这里问:
之间有什么区别
$('.sportText').text('new text added');
$('#sportText2').text('new text added2');
Run Code Online (Sandbox Code Playgroud)
我不明白 . 符号和 # 符号
?