小编Tho*_*hom的帖子

使用curl --fail获取页面输出

调用没有参数的curl,我得到页面输出,即使http状态代码= 404:

$ curl http://www.google.com/linux;
<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 404 (Not Found)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/errors/logo_sm_2.png) no-repeat}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/errors/logo_sm_2_hr.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/errors/logo_sm_2_hr.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/errors/logo_sm_2_hr.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:55px;width:150px}
  </style>
  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  <p><b>404.</b> <ins>That’s an error.</ins>
  <p>The requested URL <code>/linux</code> was not found on this server.  <ins>That’s all we know.</ins>

$ echo $?; …
Run Code Online (Sandbox Code Playgroud)

curl http wget http-post postfile

36
推荐指数
5
解决办法
2万
查看次数

Dockerfile - 使用动态值定义ENV变量

我想用动态值更新PATH环境变量.这是我到目前为止在Dockerfile中尝试过的:

...
ENV PATH '$(dirname $(find /opt -name "ruby" | grep -i bin)):$PATH'
...
Run Code Online (Sandbox Code Playgroud)

但导出显示该命令未被解释:

root@97287b22c251:/# export
declare -x PATH="\$(dirname \$(find /opt -name \"ruby\" | grep -i bin)):\$PATH"
Run Code Online (Sandbox Code Playgroud)

我不想硬编码这个值.有可能实现吗?

谢谢

dynamic environment-variables docker

6
推荐指数
2
解决办法
752
查看次数

设计模式-数据到对象

假设我在文件或数据库中有一些数据。它可以是JSON,XML,YAML,CSV,String []等。

我想用这些数据创建一个模型对象。例如:

数据:

{
    "name": "John Doe",
    "age": "30"
}
Run Code Online (Sandbox Code Playgroud)

型号(伪代码):

class Person {
    Person(name, age) {
        this.name = name;
        this.age = age;
    }
    // business logic
}
Run Code Online (Sandbox Code Playgroud)

一些从JSON数据(伪代码)创建Person对象的代码:

peopleArray = [];
recordSet = aJSONReader.read('file');
for (recordSet as r) {
    peopleArray.add(new Person(r[0], r[1]));
}
Run Code Online (Sandbox Code Playgroud)

您将使用什么根据给定的数据构建模型对象?在我的示例中,我将开始支持JSON。如果我想更改它或支持新的数据格式怎么办?如何解耦此代码?哪种设计模式适合这里?

java json design-patterns instance

5
推荐指数
1
解决办法
5096
查看次数